Commit c725a7b2 authored by Ryan Angelo G. Lim's avatar Ryan Angelo G. Lim

Added template and CSS Styling to Forum App

parent 7380380e
h1
{
color: lightblue;
font-family: 'Georgia';
position: relative;
}
h2
{
background-color: black;
color: white;
font-family: 'Georgia';
position: relative;
}
p
{
font-family: 'Verdana';
position: relative;
}
li
{
font-family: 'Verdana';
position: relative;
}
.detailsRelatedPicture
{
width: 75px;
height: 75px;
position: relative;
z-index: 999;
float: right;
}
.RectangularShadow
{
position: absolute;
left: 0px;
top: 0px;
height: 90px;
width: 100%;
background-color: gray;
}
.detailsProfilePicture
{
width: 75px;
height: 75px;
position: relative;
z-index: 999;
float: left;
}
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'forum/style.css' %}"
<title>Forum</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
{% extends "forum/base.html" %}
{% block content %}
{% if Post %}
<img src="/static/forum/{{Post.post_title}}.jpg" class="detailsRelatedPicture">
<img src="/static/forum/{{Post.post_author.last_name}}.jpg" class="detailsProfilePicture">
<div class="RectangularShadow"></div>
<h1 style="text-align: center">{{Post.post_title}}</h1>
<h2>by {{Post.post_author.first_name}} {{Post.post_author.last_name}}, {{Post.pub_date}}</h2>
<p>{{Post.post_body}}</p>
<h2>Replies:</h2>
<ul>
{% for r in reply %}
<li>{{r.reply_author.first_name}} {{r.reply_author.last_name}}, {{r.reply_pub_date}}: {{r.reply_body}}</li>
{% endfor %}
</ul>
{% else %}
<p>Post not found.</p>
{% endif %}
{% endblock %}
{% extends "forum/base.html" %}
{% block content %}
<div class="RectangularShadow"></div>
<h1 style="text-align: center">Welcome to Widget's Forum!</h1>
<h2>Forum Posts:</h2>
{% if post_list %}
<ul>
{% for Post in post_list %}
<li><a href="posts/{{Post.id}}/details">{{Post.post_title}}, by {{Post.post_author.last_name}}, {{Post.post_author.first_name}}, dated {{Post.pub_date}}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No Posts are available</p>
{% endif %}
{% endblock %}
...@@ -3,5 +3,6 @@ from django.urls import path ...@@ -3,5 +3,6 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name="forum") path('', views.index, name="forum"),
path('posts/<int:post_id>/details/', views.details, name="details"),
] ]
from django.http import HttpResponse from array import array
from django.http import HttpResponse, Http404
from forum.models import Post, Reply, WidgetUser from forum.models import Post, Reply, WidgetUser
from django.shortcuts import render
from django.template import loader
# Create your views here. # Create your views here.
def index(request): def index(request):
entries = Post.objects.all().count() post_list = Post.objects.order_by("pub_date")
n = 1 context = {
forum = "FORUM POSTS:<br/>" "post_list": post_list,
while(n<=entries): }
forum += getPost(n) return render(request, "forum/index.html", context)
forum += getReply(n)
n += 1 #entries = Post.objects.all().count()
return HttpResponse(forum) #n = 1
#forum = "FORUM POSTS:<br/>"
def getPost(pk): #while(n<=entries):
postFirstLine = "" # forum += getPost(n)
postSecondLine = "" # forum += getReply(n)
post = "" # n += 1
#return HttpResponse(forum)
postTitle = Post.objects.get(pk=pk).post_title
authorFirstName = Post.objects.get(pk=pk).post_author.first_name #def getPost(pk):
authorLastName = Post.objects.get(pk=pk).post_author.last_name # postFirstLine = ""
publicationDate = Post.objects.get(pk=pk).pub_date # postSecondLine = ""
postBody = Post.objects.get(pk=pk).post_body # post = ""
postFirstLine = "{} by {} {} dated {}:<br/>" .format(postTitle, authorFirstName, authorLastName, publicationDate)
postSecondLine = "{}<br/>" .format(postBody) # postTitle = Post.objects.get(pk=pk).post_title
post += postFirstLine + postSecondLine # authorFirstName = Post.objects.get(pk=pk).post_author.first_name
# authorLastName = Post.objects.get(pk=pk).post_author.last_name
return post # publicationDate = Post.objects.get(pk=pk).pub_date
# postBody = Post.objects.get(pk=pk).post_body
# postFirstLine = "{} by {} {} dated {}:<br/>" .format(postTitle, authorFirstName, authorLastName, publicationDate)
# postSecondLine = "{}<br/>" .format(postBody)
# post += postFirstLine + postSecondLine
# return post
def getReply(pk): def getReply(pk):
replies = "" postReply = []
for reply in Post.objects.get(pk=pk).posts.all(): for reply in Post.objects.get(pk=pk).posts.all():
replies += "Reply by {} {} {}:<br/>{}" .format(reply.reply_author.first_name, reply.reply_author.last_name, reply.reply_pub_date, reply.reply_body) postReply.append(reply)
replies += "<br/>" return postReply
replies += "<br/>"
return replies
#replies = ""
#for reply in Post.objects.get(pk=pk).posts.all():
# replies += "Reply by {} {} {}:<br/>{}" .format(reply.reply_author.first_name, reply.reply_author.last_name, reply.reply_pub_date, reply.reply_body)
# replies += "<br/>"
#replies += "<br/>"
#return replies
def details(request, post_id):
try:
post = Post.objects.get(pk=post_id)
except Post.DoesNotExist:
raise Http404("Post does not exist!")
try:
reply = getReply(pk=post_id)
except Reaction.DoesNotExist:
raise Http404("Reply does not exist")
context = {
"Post": post,
"reply": reply
}
return render(request, "forum/details.html", context)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment