Commit 2b522e43 authored by Javi Ng's avatar Javi Ng

fixed reverse_url error, added comments to all relevant files

parent 28ff3b64
...@@ -15,8 +15,9 @@ class Announcement(models.Model): ...@@ -15,8 +15,9 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
# get corresponding detail page
def get_absolute_url(self): def get_absolute_url(self):
return reverse('announcement_board:announcement-details', kwargs={'pk': self.pk}) return(reverse('announcement_board:announcementdetail', kwargs={'pk': self.pk}))
class Reaction(models.Model): class Reaction(models.Model):
......
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
{% load static %} {% load static %}
{% block title %} Add Announcement {% endblock %} {% block title %} Add Announcement {% endblock %}
{% block content %} {% block content %}
<h1> Add a new announcement: </h1> <h1> Add a new announcement: </h1>
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
{# iterate through fields in the form #}
{% for field in form%} {% for field in form%}
<b>{{ field.label }}:</b> {{ field }} <br><br> <b>{{ field.label }}:</b> {{ field }} <br><br>
{% endfor %} {% endfor %}
......
...@@ -2,19 +2,29 @@ ...@@ -2,19 +2,29 @@
{% load static %} {% load static %}
{% block title %} {{ object.title }} {% endblock %} {% block title %} {{ object.title }} {% endblock %}
{% block content %} {% block content %}
<h1> {{ object.title }} </h1> {# announcement title #}
<h2> {{ object.author.displayName }} </h2> <h1> {{ object.title }} </h1>
<h3> {{ object.pub_datetime|date:"m/d/Y, h:i A" }} </h3>
<p> {{ object.body }} </p> <br> {# announcement author using displayName method in model #}
Reactions: <h2> by {{ object.author.displayName }} </h2>
<ul>
{% for reaction in object.reactlist.all %} {# format datetime with tags #}
<li> {{ reaction.name}}: {{ reaction.tally }} </li> <h3> {{ object.pub_datetime|date:"m/d/Y, h:i A" }} </h3>
{% endfor %}
</ul> {# announcement body #}
<p> {{ object.body }} </p> <br>
{# iterate through reactions, show name: tally #}
Reactions:
<ul>
{% for reaction in object.reactlist.all %}
<li> <b>{{ reaction.name}}:</b> {{ reaction.tally }} </li>
{% endfor %}
</ul>
<form action="../edit"> <form action="../edit">
<button type="Submit">Edit Announcement</button> <button type="Submit">Edit Announcement</button>
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
{% load static %} {% load static %}
{% block title %} Edit Announcement {% endblock %} {% block title %} Edit Announcement {% endblock %}
{% block content %} {% block content %}
<h1> Edit announcement: </h1> <h1> Edit announcement: </h1>
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
{# iterate through fields #}
{% for field in form%} {% for field in form%}
<b>{{ field.label }}:</b> {{ field }} <br><br> <b>{{ field.label }}:</b> {{ field }} <br><br>
{% endfor %} {% endfor %}
......
...@@ -2,22 +2,29 @@ ...@@ -2,22 +2,29 @@
{% load static %} {% load static %}
{% block title %} Widget's Announcement Board {% endblock %} {% block title %} Widget's Announcement Board {% endblock %}
{% block content %} {% block content %}
<h1>Welcome to Widget's Announcement Board!</h1>
<h2>Announcements:</h2>
<ul>
{% for announcement in announcement_list %}
<li><a href="{{ announcement.get_absolute_url }}">{{ announcement.title }} by {{ announcement.author.displayName }}</a></li>
{% endfor %}
</ul>
<form action="./add"> <h1>Welcome to Widget's Announcement Board!</h1>
<button type="Submit">New Announcement</button>
</form> <h2>Announcements:</h2>
{# iterate through announcement_list from context, use get url function to link to detail page #}
<ul>
{% for announcement in announcement_list %}
<li><a href="{{ announcement.get_absolute_url }}">{{ announcement.title }} by {{ announcement.author.displayName }}</a></li>
{% endfor %}
</ul>
<br>
<form action="./add">
<button type="Submit">New Announcement</button>
</form>
<br>
<a href="../dashboard/">Dashboard</a> <br> <a href="../dashboard/">Dashboard</a> <br>
<a href="../forum/">Forum</a> <br> <a href="../forum/">Forum</a> <br>
<a href="../assignments/">Assignments</a> <br> <a href="../assignments/">Assignments</a> <br>
<a href="../calendar/">Calendar</a> <br> <a href="../calendar/">Calendar</a> <br>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,9 +2,16 @@ from django.urls import path ...@@ -2,9 +2,16 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
# main page listing announcements
path("", views.announcements, name="announcements"), path("", views.announcements, name="announcements"),
# detail page for each announcement
path("<int:pk>/details/", views.AnnouncementDetailView.as_view(), name="announcementdetail"), path("<int:pk>/details/", views.AnnouncementDetailView.as_view(), name="announcementdetail"),
# create page
path("add/", views.AnnouncementCreateView.as_view(), name="announcementadd"), path("add/", views.AnnouncementCreateView.as_view(), name="announcementadd"),
# edit page for each announcement
path("<int:pk>/edit/", views.AnnouncementUpdateView.as_view(), name="announcementupdate"), path("<int:pk>/edit/", views.AnnouncementUpdateView.as_view(), name="announcementupdate"),
] ]
......
...@@ -10,7 +10,7 @@ def announcements(request): ...@@ -10,7 +10,7 @@ def announcements(request):
# use context to pass announcements sorted by pubdate # use context to pass announcements sorted by pubdate
context = { context = {
"announcement_list" : Announcement.objects.all().order_by('pub_datetime'), "announcement_list" : Announcement.objects.all().order_by('-pub_datetime'),
} }
return render(request, 'announcement_board/announcements.html', context) return render(request, 'announcement_board/announcements.html', context)
......
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