Commit eb52c5d5 authored by Andre Dalwin C. Tan's avatar Andre Dalwin C. Tan

Branched Forum v2, Built Forum.html view

parent 3c204a86
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Forum {% endblock %}
{% block content %}
<h1>Welcome to Widget's Forum!</h1>
<h2>Forumposts</h2>
<ul>
{% for post in forumpost %}
<li><a href="{{ post.get_absolute_url }}">{{ post.title }} by {{ post.author.first_name }} {{ post.author.last_name }}</a></li>
{% endfor %}
</ul>
<form action="./add">
<button type="Submit">New Post</button>
</form>
<a href="../dashboard/">Dashboard</a> <br>
<a href="../announcements/">Announcements</a> <br>
<a href="../assignments/">Assignments</a> <br>
<a href="../calendar/">Calendar</a> <br>
{% endblock %}
from django.http import HttpResponse
from .models import ForumPost
from django.utils import timezone
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.shortcuts import render
def forum(request):
# fetch forum posts and replies
forum = ForumPost.objects.all()
forum_view = "Widget's Forum <br> <br> Forum Posts:<br>"
for post in forum:
post_replies = post.reply_set.all()
localdatetime = timezone.localtime(post.pub_datetime)
forum_view += """
{} by {} posted {}: <br>
{} <br>
""".format(
post.title,
post.author,
localdatetime.strftime("%m/%d/%Y, %I:%M %p"),
post.body,
)
for reply in post_replies:
localdatetime = timezone.localtime(reply.pub_datetime)
if reply.forum_post == post:
forum_view += """
Reply by {} posted {}: <br>
{} <br>
""".format(
reply.author,
localdatetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body,
)
forum_view += "<br>"
return HttpResponse(forum_view)
def forum(request):
context = {
"forumpost" : ForumPost.objects.all(), #.order_by('pub_datetime')
}
return render(request, 'forum/forum.html', context)
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