Commit 9e635913 authored by RJC's avatar RJC

modified forumpost list view and added detail view for forumpost objects

parent d8225ce7
from django.shortcuts import render
from django.http import HttpResponse
from django.views import generic
from .models import ForumPost
import pytz
from django.utils import timezone
......@@ -14,26 +14,15 @@ def convert_utc_to_local(utctime, format):
def forum_post_list_view(request):
html_string_1 = '<html lang="en"><head><meta charset="UTF-8"><title>Forum Post List</title>' \
'<h1>Forum Post List</h1></head><ul>'
html_string_2 = ''
for fp in ForumPost.objects.all():
html_string_2 += '<li><b style="font-size: 30px">{}</b>' \
' by <b style="font-size: large">{} {}</b>' \
' posted <b>{}</b><p>{}</p><ul>'.format(fp.title,
fp.author.first_name,
fp.author.last_name,
convert_utc_to_local(fp.pub_datetime,
'%d/%m/%Y %I:%M %p'),
fp.body)
for replies in fp.reply.all():
html_string_2 += '<li> Reply by <b>{} {}</b> ' \
'posted <b>{}</b><p>{}</p></li>'.format(replies.author.first_name,
replies.author.last_name,
convert_utc_to_local(replies.pub_datetime,
'%d/%m/%Y %I:%M %p'),
replies.body)
html_string_2 += '</ul></li>'
html_string_final = html_string_1 + html_string_2 + '</ul></html>'
posts = ForumPost.objects.all().order_by('-pub_datetime')
context = {
'posts': posts
}
return render(request, 'forum/forum.html', context)
return HttpResponse(html_string_final)
class ForumPostDetailView(generic.DetailView):
model = ForumPost
template_name = 'forum/forumpost-details.html'
queryset = ForumPost.objects.all()
context_object_name = 'posts'
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