Commit 06477dce authored by Migs Atienza's avatar Migs Atienza

Merge branch 'master' into 'forumv2'

Update Forumv2 with Master

See merge request !14
parents 500e5f75 0ecda9bf
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Announcement(models.Model): class Announcement(models.Model):
...@@ -9,6 +10,9 @@ class Announcement(models.Model): ...@@ -9,6 +10,9 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return '{} by {} published {}: {}'.format(self.title, self.author, self.pub_datetime, self.body) return '{} by {} published {}: {}'.format(self.title, self.author, self.pub_datetime, self.body)
def get_absolute_url(self):
return reverse('announcement:announcement-details', kwargs={'pk':self.pk})
class Reaction(models.Model): class Reaction(models.Model):
reaction_list = [("Like", "Like"), ("Heart", "Heart"), ("Angry", "Angry")] reaction_list = [("Like", "Like"), ("Heart", "Heart"), ("Angry", "Angry")]
......
{% extends 'base.html' %}
{% block title %}Add Announcement{% endblock %}
{% block content %}
<h1>Add a new announcement:</h1><br>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Announcement">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
{% extends 'base.html' %}
{% block title %}{{ announcement.title }}{% endblock %}
{% block content %}
<h1>{{ announcement.title }}</h1>
<h3>by {{ announcement.author }}</h3>
<h3> {{ announcement.pub_datetime }}</h3>
<h3> {{ announcement.body }}<br>
{% for reaction in announcement.reaction_set.all %}
{{ reaction.name }}: {{ reaction.tally }}<br>
{% endfor %}
</h3>
{% endblock %}
{% block scripts %}
<a href="/announcements/{{ announcement.pk }}/edit"><input type="submit" value="Edit Announcement"></a>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Widget's Announcement Board{% endblock %}
{% block content %}
<h1>Welcome to Widget's Announcement Board!</h1>
<h3>
{% for announcement in announcement %}
<a href="{{ announcement.get_absolute_url }}">{{ announcement.title }} by {{ announcement.author }}</a><br>
{% endfor %}
</h3>
{% endblock %}
{% block scripts %}
<a href="/announcements/add"><input type="submit" value="New Announcement"></a><br><br>
<a href="/dashboard">Dashboard</a><br>
<a href="/assignments">Assignments</a><br>
<a href="/forum">Forum</a><br>
<a href="/calendar">Calendar</a>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Edit Announcement{% endblock %}
<h1>Edit Announcement:</h1>
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from .views import index from .views import index, AnnouncementDetailView, AnnouncementCreateView, AnnouncementUpdateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('<int:pk>/details', AnnouncementDetailView.as_view(), name='announcement-details'),
path('add/', AnnouncementCreateView.as_view(), name='add-announcement'),
path('<int:pk>/edit', AnnouncementUpdateView.as_view(), name = "edit-announcement")
] ]
app_name = "announcement" app_name = "announcement"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Announcement, Reaction from .models import Announcement
def index(request): def index(request):
page_content ="""<H1>Widget's Announcement Board</H1?""" return render(request, 'announcement/announcement.html', {'announcement': Announcement.objects.all()})
for announcement in Announcement.objects.all():
newAnnouncementDateTime = announcement.pub_datetime.strftime("%m-%d-%Y %I:%M %p") class AnnouncementDetailView(DetailView):
page_content += """<br> <br> model = Announcement
{} by {} published {}:<br>
{}<br>""".format(announcement.title, announcement.author, newAnnouncementDateTime, announcement.body) def get(self, request, pk):
for reaction in Reaction.objects.all(): return render(request, 'announcement/announcement-details.html', {'announcement': self.model.objects.get(pk=pk)})
if reaction.announcement == announcement:
page_content += """<br>{}: {} class AnnouncementCreateView(CreateView):
""".format(reaction.name, reaction.tally) model = Announcement
return HttpResponse(page_content) fields = '__all__'
template_name = 'announcement/announcement-add.html'
class AnnouncementUpdateView(UpdateView):
model = Announcement
fields = '__all__'
template_name = 'announcement/announcement-edit.html'
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
{% block scripts %} {% block scripts %}
<a href="/assignments/add"><input type="submit" value="New Assignment"></a><br><br> <a href="/assignments/add"><input type="submit" value="New Assignment"></a><br><br>
<a href="/dashboard">Dashboard</a><br> <a href="/dashboard">Dashboard</a><br>
<a href="/announcement">Announcements</a><br> <a href="/announcements">Announcements</a><br>
<a href="/forum">Forum</a><br> <a href="/forum">Forum</a><br>
<a href="/calendar">Calendar</a> <a href="/calendar">Calendar</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<a href="/dashboard/widgetusers/add"><input type="submit" value="Add Widget User"></a><br> <a href="/dashboard/widgetusers/add"><input type="submit" value="Add Widget User"></a><br>
<a href="/announcement">Announcement Board</a><br> <a href="/announcements">Announcement Board</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> <a href="/calendar">Calendar</a>
......
No preview for this file type
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
{% block scripts %} {% block scripts %}
<a href="/forum/forumposts/add"><input type="submit" value="New Post"></a><br><br> <a href="/forum/forumposts/add"><input type="submit" value="New Post"></a><br><br>
<a href="/dashboard">Dashboard</a><br> <a href="/dashboard">Dashboard</a><br>
<a href="/announcement">Announcements</a><br> <a href="/announcements">Announcements</a><br>
<a href="/assignments">Assignments</a><br> <a href="/assignments">Assignments</a><br>
<a href="/calendar">Calendar</a> <a href="/calendar">Calendar</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
{% block scripts %} {% block scripts %}
<a href="/calendar/events/add"><input type="submit" value="New Activity"></a><br><br> <a href="/calendar/events/add"><input type="submit" value="New Activity"></a><br><br>
<a href="/dashboard">Dashboard</a><br> <a href="/dashboard">Dashboard</a><br>
<a href="/announcement">Announcement Board</a><br> <a href="/announcements">Announcement Board</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>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,7 +2,7 @@ from django.contrib import admin ...@@ -2,7 +2,7 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('announcement/', include('announcement.urls', namespace="announcement")), path('announcements/', include('announcement.urls', namespace="announcement")),
path('calendar/', include('widget_calendar.urls', namespace="widget_calendar")), path('calendar/', include('widget_calendar.urls', namespace="widget_calendar")),
path('assignments/', include('assignments.urls', namespace="assignments")), path('assignments/', include('assignments.urls', namespace="assignments")),
path('dashboard/', include('dashboard.urls', namespace="dashboard")), path('dashboard/', include('dashboard.urls', namespace="dashboard")),
......
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