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