Commit 4d610360 authored by Neal Berones's avatar Neal Berones

update: updated detail.html of announcements app templates

parent 208546e5
...@@ -3,33 +3,14 @@ ...@@ -3,33 +3,14 @@
{% block page-title %}Announcements Page{% endblock %} {% block page-title %}Announcements Page{% endblock %}
{% block content %} {% block content %}
<head> <head>
<h1>{{ announcement.announcement_title }}</h1> <h1>{{ announcement.announcement_title }}</h1>
<h2>by {{ announcement.author.first_name }} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"SHORT_DATE_FORMAT" }}</h2> <h2>by {{ announcement.author.first_name }} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"SHORT_DATE_FORMAT" }}</h2>
</head> </head>
<body> <body>
<p>{{ announcement.announcement_body }}</p> <p>{{ announcement.announcement_body }}</p>
<script> <p>Like: {{ like_tally }}</p>
var like = 0; <p>Love: {{ love_tally }}</p>
var love = 0; <p>Angry: {{ angry_tally }}</p>
var angry = 0; </body>
for (let r in reaction_list){
if (r.reaction_name == "Like"){
like++;
}
else if (r.reaction_name == "Love"){
love++;
}
else if (r.reaction_name == "Angry"){
angry++;
}
}
document.getElementById("Like").innerHTML = like;
document.getElementById("Love").innerHTML = love;
document.getElementById("Angry").innerHTML = angry;
</script>
<p id = "Like"></p>
<p id = "Love"></p>
<p id = "Angry"></p>
{% endblock %} {% endblock %}
...@@ -4,6 +4,6 @@ from . import views ...@@ -4,6 +4,6 @@ from . import views
app_name = "announcements" app_name = "announcements"
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('/announcements/<int:announcement_id>/detail', views.detail, name="detail") path('<int:announcement_id>/details', views.detail, name="detail")
#path('welcome', views.welcome, name='welcome') #path('welcome', views.welcome, name='welcome')
] ]
...@@ -16,17 +16,30 @@ def index(request): ...@@ -16,17 +16,30 @@ def index(request):
def detail(request, announcement_id): def detail(request, announcement_id):
try: try:
announcement = Announcement.objects.get(pk=announcement_id) announcement = Announcement.objects.get(pk=announcement_id)
reaction_list = Reaction.objects.get(announcment_id=announcement_id) reaction_list = Reaction.objects.all()
except Announcement.DoesNotExist: except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!") raise Http404("Announcement does not exist!")
like_tally=0
love_tally=0
angry_tally=0
for r in reaction_list:
if r.reaction_name=="Like" and r.announcement==announcement:
like_tally+=r.tally
elif r.reaction_name=="Love" and r.announcement==announcement:
love_tally+=r.tally
elif r.reaction_name=="Angry" and r.announcement==announcement:
angry_tally+=r.tally
context = { context = {
"announcement": announcement, "announcement": announcement,
"reaction_list": reaction_list "like_tally": like_tally,
"love_tally": love_tally,
"angry_tally": angry_tally
} }
return render(request, "announcements/detail.html", context) return render(request, "announcements/details.html", context)
# Code from previous lab activities: # Code from previous lab activities:
#def welcome(request): # def welcome(request):
# return HttpResponse("This is the Announcement Board!") # return HttpResponse("This is the Announcement Board!")
# announcement_view = 'ANNOUNCEMENTS: ' # announcement_view = 'ANNOUNCEMENTS: '
......
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