Commit d56aa856 authored by shibadisaster's avatar shibadisaster

Added view for forum posts

parent cda4fa9e
......@@ -35,4 +35,4 @@ def index(request):
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
\ No newline at end of file
return HttpResponse(return_string)
......@@ -16,6 +16,9 @@ class ForumPost(models.Model):
def __str__(self):
return self.title
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
class Reply(models.Model):
post = models.ForeignKey(
ForumPost,
......@@ -34,4 +37,7 @@ class Reply(models.Model):
def __str__(self):
return self.body
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
# appname/views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
from dashboard.models import WidgetUser
def index(request):
return HttpResponse('Hello World! This came from the forum view')
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:450%;'>\
Widget Forum\
</h1>"
body = "<h2>Forum Posts:</h2>"
for post in ForumPost.objects.all():
body += "<div style='border: 2px solid gray; border-radius:5px; padding:20px 30px;'>\
<b>{}</b> by {} {} posted {}:\
<br>\
{}".format(post.title, post.author.first_name, post.author.last_name, post.format_pub_datetime(), post.body)
for reply in Reply.objects.all():
if reply.post == post:
body += "<p style='border: 1px dashed gray; border-radius:5px; padding:20px 30px;'>\
Reply by {} {} posted {}:\
<br>\
{}".format(reply.author.first_name, reply.author.last_name, reply.format_pub_datetime(), reply.body)
body += "</div>"
body += "<p>&nbsp;</p>"
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
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