Commit 0108d3cb authored by Bryan Carlo Guanlao's avatar Bryan Carlo Guanlao

updated Announcement view

Announcement view now displays announcements and its reactions
parent 73953eaa
...@@ -29,5 +29,5 @@ class Reaction(models.Model): ...@@ -29,5 +29,5 @@ class Reaction(models.Model):
) )
tally = models.IntegerField() tally = models.IntegerField()
def _str_(self): def __str__(self):
return '{}: {}'.format(self.reaction_name, self.tally) return '{}'.format(self.reaction_name)
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import Http404, HttpRequest, HttpResponse
from .models import Announcement, Reaction, WidgetUser
def get_reactions(a):
reaction = ''
like = Reaction.objects.filter(reaction_name='Like', announcement=a)
love = Reaction.objects.filter(reaction_name='Love', announcement=a)
hate = Reaction.objects.filter(reaction_name='Hate', announcement=a)
for l in like:
reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>'
for l in love:
reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>'
for h in hate:
reaction += '{}: '.format(h) + '{}'.format(h.tally) + '<br>'
return reaction
def announcements(request): def announcements(request):
return HttpResponse("This is the Announcement Board!") text = 'ANNOUNCEMENTS:<br>'
for announcement in Announcement.objects.all():
text += (
'{} '.format(announcement)
+ 'by {} {} '.format(announcement.author.first_name,
announcement.author.last_name)
+ 'dated {}').format(announcement.pub_date.strftime('%x')
+ ':<br>'
+ '{}<br>'.format(announcement.announcement_body)
+ get_reactions(announcement)
+ '<br>'
)
return HttpResponse(text)
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