Commit 36825a81 authored by justin's avatar justin

Fixed view (formatting datetime and casting str to reaction.tally)

parent f38b8c23
from django.http import HttpResponse
from .models import Announcement, Reaction
from datetime import datetime
# Create your views here.
def announcements(request):
# retrieve all announcement entries in a list
announcementList = Announcement.objects.all()
# build response string
response = "Widget's Announcement Board <br>" + "Announcements:"
response = "Widget's Announcement Board <br><br>" + "Announcements:"
for announcement in announcementList:
# string formatting for date-time
datetime = announcement.pub_datetime("%m/%d/%Y, %I:%M %p")
datetime = announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
# list of reactions for announcement
reactions = announcement.reaction_set.all()
# response proper
response = response + "<br>" + announcement.name + " by " + announcement.author + " published " + datetime + ": <br>"
response = (
response
+ "<br>"
+ announcement.title
+ " by "
+ announcement.author.displayName()
+ " published "
+ datetime
+ ": <br>"
)
response = response + announcement.body + "<br>"
# for each reaction, add line with reaction and tally
for reaction in reactions:
response = response + reaction.name + ": " + reaction.tally + "<br>"
response = response + reaction.name + ": " + str(reaction.tally) + "<br>"
return HttpResponse(response)
\ No newline at end of file
return HttpResponse(response)
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