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

update: updated detail.html of announcements app templates

parent 208546e5
......@@ -3,33 +3,14 @@
{% block page-title %}Announcements Page{% endblock %}
{% block content %}
<head>
<h1>{{ announcement.announcement_title }}</h1>
<h2>by {{ announcement.author.first_name }} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"SHORT_DATE_FORMAT" }}</h2>
</head>
<body>
<p>{{ announcement.announcement_body }}</p>
<script>
var like = 0;
var love = 0;
var angry = 0;
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>
<head>
<h1>{{ announcement.announcement_title }}</h1>
<h2>by {{ announcement.author.first_name }} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"SHORT_DATE_FORMAT" }}</h2>
</head>
<body>
<p>{{ announcement.announcement_body }}</p>
<p>Like: {{ like_tally }}</p>
<p>Love: {{ love_tally }}</p>
<p>Angry: {{ angry_tally }}</p>
</body>
{% endblock %}
......@@ -4,6 +4,6 @@ from . import views
app_name = "announcements"
urlpatterns = [
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')
]
......@@ -16,17 +16,30 @@ def index(request):
def detail(request, announcement_id):
try:
announcement = Announcement.objects.get(pk=announcement_id)
reaction_list = Reaction.objects.get(announcment_id=announcement_id)
reaction_list = Reaction.objects.all()
except Announcement.DoesNotExist:
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 = {
"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:
#def welcome(request):
# def welcome(request):
# return HttpResponse("This is the Announcement Board!")
# 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