Commit d56aa856 authored by shibadisaster's avatar shibadisaster

Added view for forum posts

parent cda4fa9e
...@@ -16,6 +16,9 @@ class ForumPost(models.Model): ...@@ -16,6 +16,9 @@ class ForumPost(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
class Reply(models.Model): class Reply(models.Model):
post = models.ForeignKey( post = models.ForeignKey(
ForumPost, ForumPost,
...@@ -35,3 +38,6 @@ class Reply(models.Model): ...@@ -35,3 +38,6 @@ class Reply(models.Model):
def __str__(self): def __str__(self):
return self.body return self.body
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
# appname/views.py # appname/views.py
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import ForumPost, Reply
from dashboard.models import WidgetUser
def index(request): 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