Commit 6024ab4b authored by Paul Angelo Sy's avatar Paul Angelo Sy

Merge branch 'master' of...

Merge branch 'master' of https://gitlab.discs.ateneo.edu/rangelo/widget-tee-jays-angelos into sy/assignments
parents 4611b35a 3249206e
{% if Announcement %}
<h2>{{Announcement.announcement_title}}</h2>
<h3>by {{Announcement.author.first_name}} {{Announcement.author.last_name}}, {{Announcement.pub_date}}</h3>
<h4>{{Announcement.announcement_body}}</h4>
{% for reaction in reactions %}
<h4>{{reaction.reaction_name}}: {{reaction.tally}}</h4>
{% endfor %}
{% else %}
<p>Announcement not found.</p>
{% endif %}
\ No newline at end of file
{% if announcement_list %}
<h1>Announcement Board</h1>
<h2>Important Announcements:</h2>
<ul>
{% for Announcement in announcement_list %}
<li><a href="/announcements/{{Announcement.id}}/details">{{Announcement.announcement_title}}, by {{Announcement.author.last_name}}, {{Announcement.author.first_name}}, dated {{Announcement.pub_date}}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No Announcements are available</p>
{% endif %}
\ No newline at end of file
...@@ -2,5 +2,6 @@ from django.urls import path ...@@ -2,5 +2,6 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name="announcements") path('', views.index, name="announcements"),
path('<int:announcement_id>/details/', views.details, name="details"),
] ]
from django.http import HttpResponse from array import array
from django.http import HttpResponse, Http404
from announcements.models import Announcement, Reaction, WidgetUser from announcements.models import Announcement, Reaction, WidgetUser
from django.shortcuts import render
from django.template import loader
# Create your views here. # Create your views here.
def index(request): def index(request):
announcementEntries = Announcement.objects.all().count() # announcementEntries = Announcement.objects.all().count()
n = 1 # n = 1
announcement = "ANNOUNCEMENTS:<br/>" # announcement = "ANNOUNCEMENTS:<br/>"
while(n<=announcementEntries): # while(n<=announcementEntries):
announcement += getAnnouncementHeader(n) # announcement += getAnnouncementHeader(n)
announcement += getReactions(n) # announcement += getReactions(n)
n += 1 # n += 1
return HttpResponse(announcement) # return HttpResponse(announcement)
announcement_list = Announcement.objects.order_by("pub_date")
context = {
"announcement_list": announcement_list,
}
return render(request, "announcements/index.html", context)
# helper function that iterates through every reaction of an announcement and returns it # helper function that iterates through every reaction of an announcement, adds it to an array, then returns it
def getReactions(pk): def getReactions(pk):
announcementReactions = "" # announcementReactions = ""
# for reaction in Announcement.objects.get(pk=pk).announcements.all():
# announcementReactions += "{}: {}<br/>" .format(reaction.reaction_name, reaction.tally)
# announcementReactions += "<br/> "
# return announcementReactions
# announcementReactions = ""
announcementReactions = []
for reaction in Announcement.objects.get(pk=pk).announcements.all(): for reaction in Announcement.objects.get(pk=pk).announcements.all():
announcementReactions += "{}: {}<br/>" .format(reaction.reaction_name, reaction.tally) announcementReactions.append(reaction)
announcementReactions += "<br/> "
return announcementReactions return announcementReactions
# helper function that takes the data in an announcement and creates the header of the announcement # helper function that takes the data in an announcement and creates the header of the announcement
# (First and Second lines) # (First and Second lines)
def getAnnouncementHeader(pk): # def getAnnouncementHeader(pk):
announcementFirstLine = "" # announcementFirstLine = ""
announcementSecondLine = "" # announcementSecondLine = ""
announcementHeader = "" # announcementHeader = ""
# announcementTitle = Announcement.objects.get(pk=pk).announcement_title
# authorFirstName = Announcement.objects.get(pk=pk).author.first_name
# authorLastName = Announcement.objects.get(pk=pk).author.last_name
# publicationDate = Announcement.objects.get(pk=pk).pub_date
# announcementBody = Announcement.objects.get(pk=pk).announcement_body
# announcementFirstLine = "{} by {} {} dated {}:<br/>" .format(announcementTitle, authorFirstName, authorLastName, publicationDate)
# announcementSecondLine = "{}<br/>" .format(announcementBody)
# announcementHeader += announcementFirstLine + announcementSecondLine
announcementTitle = Announcement.objects.get(pk=pk).announcement_title # return announcementHeader
authorFirstName = Announcement.objects.get(pk=pk).author.first_name
authorLastName = Announcement.objects.get(pk=pk).author.last_name
publicationDate = Announcement.objects.get(pk=pk).pub_date
announcementBody = Announcement.objects.get(pk=pk).announcement_body
announcementFirstLine = "{} by {} {} dated {}:<br/>" .format(announcementTitle, authorFirstName, authorLastName, publicationDate)
announcementSecondLine = "{}<br/>" .format(announcementBody)
announcementHeader += announcementFirstLine + announcementSecondLine
return announcementHeader def details(request, announcement_id):
try:
announcement = Announcement.objects.get(pk=announcement_id)
except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!")
try:
reactions = getReactions(pk=announcement_id)
except Reaction.DoesNotExist:
raise Http404("Reaction does not exist")
context = {
"Announcement": announcement,
"reactions": reactions
}
return render(request, "announcements/details.html", context)
\ No newline at end of file
...@@ -31,6 +31,9 @@ DEBUG = True ...@@ -31,6 +31,9 @@ DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
# Change Date Format
DATE_FORMAT = "m-d-Y"
USE_L10N = False
# Application definition # Application definition
......
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