Commit e2232aac authored by Julia Anishka's avatar Julia Anishka

updated views, url and created template for announcements page

parent 859a772a
{% extends 'base.html' %}
{% block title %} Widget's Announcement Board {% endblock %}
{% block header %}
<h1> Welcome to Widget's Announcement Board! </h1>
{% endblock %}
{% block content %}
<h2> Announcements: </h2><br>
<div>
<ul>
{% for announcement in announcements %}
<li>
<a href="{{ announcement.get_absolute_url }}">
{{ announcement.title }} by {{ announcement.author.first_name }} {{ announcement.author.last_name }}
</a>
</li>
{% endfor %}
</ul>
</div>
<div>
<a href="/announcements/announcements/add/"> New Announcement </a>
</div>
<a href="/dashboard/"> Dashboard </a>
<a href="/forum/"> Forum </a>
<a href="/assignments/"> Assignments </a>
<a href="/calendar/"> Calendar </a>
{% endblock %}
\ No newline at end of file
...@@ -2,5 +2,5 @@ from django.urls import path ...@@ -2,5 +2,5 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.announcement_view, name='announcements'),
] ]
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render
from .models import Announcement, Reaction from .models import Announcement, Reaction
def index(request): def announcement_view(request):
all_announcements = Announcement.objects.all() announcements = Announcement.objects.order_by('-pub_datetime')
all_reactions = Reaction.objects.all() context = {
welcomeMessage = 'Widget\'s Announcement Board<br><br>Announcements:<br>' 'announcements': announcements
response = '' }
for announcement in all_announcements: return render(request, 'announcementboard/announcements.html', context)
reactions = ''
reactions_list = {'Like':0, 'Love':0, 'Angry':0}
for reaction in all_reactions:
if reaction.announcement.title == announcement.title:
reactions_list[reaction.name] = reaction.tally
keys = list(reactions_list.keys())
for key in keys:
reactions += key + ': ' + str(reactions_list[key]) + '<br>'
datetime = announcement.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
author = announcement.author.first_name + ' '+ announcement.author.last_name
response += announcement.title + ' by ' + author + ' published ' + datetime
response += ':' + '<br>' + announcement.body + '<br>' + reactions + '<br>'
return HttpResponse(welcomeMessage + response)
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