Commit e92d174c authored by Jiuvi Anne Hu's avatar Jiuvi Anne Hu

Updated templates, view, and url.

parent 0e90f3f3
......@@ -3,7 +3,12 @@
{% block content %}
<title>Add Announcement</title>
<title>Add Announcement</title>
<h1>Add a new announcement:</h1>
<form action="/" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock content %}
\ No newline at end of file
......@@ -3,7 +3,17 @@
{% block content %}
<title>Widget's Announcement Board</title>
<title>{{announcement.title}}</title>
<h1>{{announcement.title}}</h1><br>
<h2>by</h2><br>
<p>{{ announcement.body }}</p><br>
<p>
{% for reaction in reaction.model.all %}
{{ reaction. name }}: {{ reaction.tally }}<br>
{% endfor %}
</p>
<a href = "announcements/<int:pk>/edit/"><button value="">Edit Announcement</button></a>
{% endblock content %}
\ No newline at end of file
......@@ -3,7 +3,12 @@
{% block content %}
<title>Edit Announcement</title>
<title>Edit Announcement</title>
<h1>Edit announcement:</h1>
<form action="/" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock content %}
\ No newline at end of file
......@@ -3,12 +3,19 @@
{% block content %}
<title>Widget's Announcement Board</title>
<h1>Welcome to Widget's Announcement Board!</h1>
<title>Widget's Announcement Board</title>
<h1>Welcome to Widget's Announcement Board!</h1>
<a href = "/Dashboard/">Dashboard</a><br>
<a href = "/forum/">Forum</a><br>
<a href = "/Assignments/">Assignments</a><br>
<a href = "/widget_Calendar/">Calendar</a>
<h3>Announcements:</h3>
{% for announcement in announcements %}
<a href = "{{announcement.pk}}/details/">{{ announcement.title }} by {{ announcement.author.first_name }} {{ announcement.author.last_name }}</a><br>
{% endfor %} <br>
<a href="announcements/add/"><button value="click here">Add Announcement</button></a>
<a href = "/Dashboard/">Dashboard</a><br>
<a href = "/forum/">Forum</a><br>
<a href = "/Assignments/">Assignments</a><br>
<a href = "/widget_Calendar/">Calendar</a>
{% endblock content %}
\ No newline at end of file
......@@ -2,7 +2,10 @@ from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
path('announcements/', index, name='index'),
path('announcements/<int:pk>/details/', AnnouncementDetailView.as_view(), name='announcement-detail'),
path('announcements/add/', AnnouncementDetailView.as_view(), name='announcement-add'),
path('announcements/<int:pk>/edit/', AnnouncementDetailView.as_view(), name='announcement-edit'),
]
app_name = "announcements"
\ No newline at end of file
......@@ -6,29 +6,41 @@ from django.utils import timezone
def convert_to_localtime(utctime):
format = '%d/%m/%Y %I:%M %p'
format = '%m/%d/%Y %I:%M %p'
utc = utctime.replace(tzinfo=pytz.UTC)
localtz = utc.astimezone(timezone.get_current_timezone())
return localtz.strftime(format)
def index(request):
html_string_1 = '<html lang="en"><head><meta charset="UTF-8"></head>\
<b><h1>Widget\'s Announcement Board</h1></b>\
<h2>Announcements:</h2><br/>'
html_string_2 = ""
for announced in Announcement.objects.all():
html_string_2 += "{} by {} {} published {}:<br />\
{}<br/>".format(announced.title, announced.author.first_name,
announced.author.last_name,
convert_to_localtime(announced.pub_datetime), announced.body)
for reacts in announced.reaction_set.all():
html_string_2 += "{}: {}<br/>".format(reacts.name, reacts.tally)
html_string_2 += '<br/>'
html_string_final = html_string_1 + html_string_2 + "</html>"
return HttpResponse(html_string_final)
announcement = Announcement.objects.all().order_by('-pub_datetime')
context = {
'announcement': announcement
}
return render(request, 'announcements/announcements.html', context)
class AnnouncementDetailView(DetailView)
model = Announcement
template_name = 'announcements/announcement-detail.html'
queryset = Annoucement.objects.all()
context_object_name = 'annoucement-details'
class AnnouncementAddView(CreateView)
model = Announcement
fields = '__all__'
template_name = 'announcement-add.html'
def get_success_url(self):
return reverse('announcement:announcementdetailview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class AnnouncementEditView(UpdateView)
model = Announcement
template_name = 'announcements/announcement-edit'
def get_success_url(self):
return reverse('announcement:announcementdetailview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
# Create your views here.
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