Commit 7cc4c2cc authored by Jayson Lim's avatar Jayson Lim

Implemented view according to the guidelines

parent 426d6222
...@@ -8,18 +8,19 @@ class Announcement(models.Model): ...@@ -8,18 +8,19 @@ class Announcement(models.Model):
WidgetUser, WidgetUser,
null=True, null=True,
default=True, default=True,
on_delete=models.SET_DEFAULT on_delete=models.SET_DEFAULT,
) )
pub_datetime = models.DateTimeField(auto_now_add=True) pub_datetime = models.DateTimeField(auto_now_add=True)
def __str__(self): def __str__(self):
return self.title return self.title
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
class Reaction(models.Model): class Reaction(models.Model):
name = models.CharField(max_length=5, choices=[ name = models.CharField(max_length=5, default='')
('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')], default='Like')
tally = models.PositiveIntegerField(default=0) tally = models.PositiveIntegerField(default=0)
annoucement = models.ForeignKey( annoucement = models.ForeignKey(
Announcement, Announcement,
......
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement
from .models import Reaction
def index(request): def index(request):
return HttpResponse('placeholder')
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:450%;'>\
Widget's Announcement Board\
</h1>"
body = "<h2>Announcements:</h2>"
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
for i in range(0, len(announcements), 1):
announcement = announcements[i]
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
{} by {} published {}:\
<br>\
{}\
</p>".format(announcement.title, announcement.author,
announcement.format_pub_datetime(), announcement.body)
for j in range(i * 3, (i + 1) * 3):
if j >= len(reactions):
break
reaction = reactions[j]
body += "<p>{}: {}\
</p>".format(reaction.name, reaction.tally)
body += '<p>&nbsp;</p>'
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
\ 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