Commit d1ab89bb authored by Alliyah Marcelo's avatar Alliyah Marcelo

Modified views.py for FBV and CBV implementations of the respective Forum app pages.

parent 7da5c966
from django.http import HttpResponse
from .models import ForumPost, Reply
def index(request):
return_string = "<p>Widget's Forum</p>Forum Posts:"
for post in ForumPost.objects.all():
counter = 0
for reply in Reply.objects.all():
if counter == 0 and post.title == reply.forumpost.title:
return_string += '<br>{} by {} {} posted {}<br>{}'.format(
reply.forumpost.title,
reply.forumpost.author.first_name,
reply.forumpost.author.last_name,
reply.forumpost.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
reply.forumpost.body,
)
return_string += '<br>Reply by {} {} posted {}<br>{}'.format(
reply.author.first_name,
reply.author.last_name,
reply.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
reply.body,
)
counter += 1
continue
elif counter == 1 and post.title == reply.forumpost.title:
return_string += '<br>Reply by {} {} posted {}<br>{}'.format(
reply.author.first_name,
reply.author.last_name,
reply.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
reply.body,
)
continue
elif counter == 1 and post.title != reply.forumpost.title:
return_string += '<br>'
break
else:
continue
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import ForumPost
def forum(request):
posts = ForumPost.objects.all()
return render(request, 'forum/forum.html', {'posts': posts})
class ForumPostDetailView(DetailView):
model = ForumPost
template_name = 'forum/forumpost-details.html'
class ForumPostCreateView(CreateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-add.html'
class ForumPostUpdateView(UpdateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-edit.html'
\ No newline at end of file
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