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

Updated templates, view, and url.

parent 0e90f3f3
...@@ -3,7 +3,12 @@ ...@@ -3,7 +3,12 @@
{% block content %} {% 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 %} {% endblock content %}
\ No newline at end of file
...@@ -3,7 +3,17 @@ ...@@ -3,7 +3,17 @@
{% block content %} {% 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 %} {% endblock content %}
\ No newline at end of file
...@@ -3,7 +3,12 @@ ...@@ -3,7 +3,12 @@
{% block content %} {% 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 %} {% endblock content %}
\ No newline at end of file
...@@ -3,12 +3,19 @@ ...@@ -3,12 +3,19 @@
{% block content %} {% block content %}
<title>Widget's Announcement Board</title> <title>Widget's Announcement Board</title>
<h1>Welcome to Widget's Announcement Board!</h1> <h1>Welcome to Widget's Announcement Board!</h1>
<a href = "/Dashboard/">Dashboard</a><br> <h3>Announcements:</h3>
<a href = "/forum/">Forum</a><br> {% for announcement in announcements %}
<a href = "/Assignments/">Assignments</a><br> <a href = "{{announcement.pk}}/details/">{{ announcement.title }} by {{ announcement.author.first_name }} {{ announcement.author.last_name }}</a><br>
<a href = "/widget_Calendar/">Calendar</a> {% 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 %} {% endblock content %}
\ No newline at end of file
...@@ -2,7 +2,10 @@ from django.urls import path ...@@ -2,7 +2,10 @@ from django.urls import path
from .views import index from .views import index
urlpatterns = [ 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" app_name = "announcements"
\ No newline at end of file
...@@ -6,29 +6,41 @@ from django.utils import timezone ...@@ -6,29 +6,41 @@ from django.utils import timezone
def convert_to_localtime(utctime): 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) utc = utctime.replace(tzinfo=pytz.UTC)
localtz = utc.astimezone(timezone.get_current_timezone()) localtz = utc.astimezone(timezone.get_current_timezone())
return localtz.strftime(format) return localtz.strftime(format)
def index(request): def index(request):
html_string_1 = '<html lang="en"><head><meta charset="UTF-8"></head>\ announcement = Announcement.objects.all().order_by('-pub_datetime')
<b><h1>Widget\'s Announcement Board</h1></b>\ context = {
<h2>Announcements:</h2><br/>' 'announcement': announcement
}
html_string_2 = "" return render(request, 'announcements/announcements.html', context)
for announced in Announcement.objects.all():
html_string_2 += "{} by {} {} published {}:<br />\ class AnnouncementDetailView(DetailView)
{}<br/>".format(announced.title, announced.author.first_name, model = Announcement
announced.author.last_name, template_name = 'announcements/announcement-detail.html'
convert_to_localtime(announced.pub_datetime), announced.body) queryset = Annoucement.objects.all()
for reacts in announced.reaction_set.all(): context_object_name = 'annoucement-details'
html_string_2 += "{}: {}<br/>".format(reacts.name, reacts.tally)
html_string_2 += '<br/>' class AnnouncementAddView(CreateView)
model = Announcement
html_string_final = html_string_1 + html_string_2 + "</html>" fields = '__all__'
template_name = 'announcement-add.html'
return HttpResponse(html_string_final) 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. # 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