Commit 66c82467 authored by Fritzie Dianne Del Pilar's avatar Fritzie Dianne Del Pilar

Merge branch 'announcementboardv2'

parents df7b36fe 989a22a7
...@@ -4,14 +4,14 @@ Del Pilar, Fritzie Dianne, B., 211983 ...@@ -4,14 +4,14 @@ Del Pilar, Fritzie Dianne, B., 211983
Salto, Mary Adelaide, A., 215208 Salto, Mary Adelaide, A., 215208
Tan, Lance Cedric B., 204954 Tan, Lance Cedric B., 204954
Midterm Proj: Widget v1 Midterm Proj: Widget v2
App Assignments: App Assignments:
Del Pilar - Git Repo, Django Project, and Announcement Board Del Pilar - Announcementboard.v2
Salto - Dashboard Salto - Dashboard.v2
Tan - Forum Tan - Forum.v2
Date of Submission: March 6, 2023 Date of Submission: May 15, 2023
We, members of CtrlF, truthfully completed this project with all our efforts and knowledge. We, members of CtrlF, truthfully completed this project with all our efforts and knowledge.
...@@ -21,6 +21,6 @@ DateTimeField - https://www.geeksforgeeks.org/datetimefield-django-forms/ ...@@ -21,6 +21,6 @@ DateTimeField - https://www.geeksforgeeks.org/datetimefield-django-forms/
Members' Signature: Members' Signature:
(sgd) Del Pilar, Fritzie Dianne B., March 6, 2023 (sgd) Del Pilar, Fritzie Dianne B., May 15, 2023
(sgd) Salto, Mary Adelaide A., March 6, 2023 (sgd) Salto, Mary Adelaide A., MMay 15, 2023
(sgd) Tan, Lance Cedric B., March 6, 2023 (sgd) Tan, Lance Cedric B., May 15, 2023
\ No newline at end of file \ No newline at end of file
...@@ -3,4 +3,4 @@ from django.apps import AppConfig ...@@ -3,4 +3,4 @@ from django.apps import AppConfig
class AnnouncementBoardConfig(AppConfig): class AnnouncementBoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = 'django.db.models.BigAutoField'
name = 'announcement_board' name = 'announcements'
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
from django.urls import reverse
Like = 'Like'
Love = 'Love'
Angry = 'Angry'
REACTIONS = ((Like, 'Like'),
(Love, 'Love'),
(Angry, 'Angry'))
class Announcement(models.Model): class Announcement(models.Model):
...@@ -16,14 +10,59 @@ class Announcement(models.Model): ...@@ -16,14 +10,59 @@ class Announcement(models.Model):
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField(default=timezone.now, null=True, blank=True) pub_datetime = models.DateTimeField(default=timezone.now, null=True, blank=True)
def __str__(self): def date_format(self):
return self.title return '{}' .format(self.pub_datetime.strftime("%m/%d/%Y"))
def time_format(self):
return '{}' .format(self.pub_datetime.strftime("%H:%M %p"))
def getLike(self):
try:
return '{}'.format(Reaction.objects.get(name="Like", announcement=self).tally)
except:
return '0'
def getLove(self):
try:
return '{}'.format(Reaction.objects.get(name="Love", announcement=self).tally)
except:
return '0'
def getAngry(self):
try:
return '{}'.format(Reaction.objects.get(name="Angry", announcement=self).tally)
except:
return '0'
def get_absolute_url(self):
return reverse(
'announcements:announcement-details',
kwargs={'pk': self.pk},
)
def __str__(self):
return '{} by {} {} published {}, {}: {}'.format(
self.title,
self.author.first_name,
self.author.last_name,
self.pub_datetime.strftime("%m/%d/%Y"),
self.pub_datetime.strftime("%H:%M %p"),
self.body,
)
class Reaction(models.Model): class Reaction(models.Model):
Like = 'Like'
Love = 'Love'
Angry = 'Angry'
REACTIONS = [
((Like, 'Like'),
(Love, 'Love'),
(Angry, 'Angry'))
]
name = models.CharField(max_length=10, choices=REACTIONS, default=Like) name = models.CharField(max_length=10, choices=REACTIONS, default=Like)
tally = models.IntegerField(default = 0) tally = models.IntegerField(default = 0)
announcement = models.ForeignKey(Announcement, on_delete = models.CASCADE) announcement = models.ForeignKey(Announcement, on_delete = models.CASCADE)
def __str__(self): def __str__(self):
return self.name return '{} reactions for {}' .format(self.name, self.announcement)
\ No newline at end of file \ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %}Add Announcement:{% endblock %}
{% block heading %}<h1>Add a new announcement:</h1>{% endblock %}
{% block content %}
<form method="POST" action="{% url 'announcements:add' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ announcement_form.as_table }}
<p>
<input class="button" type="submit" value="Add Announcement">
</p>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<p>
by {{ object.author.first_name }} {{ object.author.last_name }}<br>
</p>
<p>
{{ object.format_date}}, {{ object.format_time }}<br><br>
{{ object.body }}<br>
Like: {{ object.getLike }}<br>
Love: {{ object.getLove }}<br>
Angry: {{ object.getAngry}} <br>
</p>
<p>
<a href="/announcements/{{object.pk}}/edit">
<button class="btn">Edit Announcement</button>
</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %}Edit Announcement{% endblock %}
{% block heading %}<h1>Edit announcement:</h1>{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table><br><br>
<input class="button" type="submit" value="Save Changes to Announcement">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %} Widget's Announcement Board {% endblock %}
{% block heading %} <h1> Welcome to Widget's Announcement Board! </h1> {% endblock %}
{% block content %}
<p> Announcements:<br>
{% for a in announcements_list %}
<a href="{% url 'announcements:detail' announcement.id %}">
{{a.title}} by {{ a.author.first_name }} {{ a.author.last_name }}
</a><br>
{% endfor %}
</p>
{% endblock %}
{% block footing %}
<p>
<a href="/announcements/add">
<button class="btn add">New Announcement</button>
</a>
</p>
<p>
<a href="/dashboard/" class="link">Dashboard</a><br>
<a href="/forum/" class="link">Forum</a><br>
<a href="/assignments/" class="link">Assignments</a><br>
<a href="/calendar/" class="link">Calendar</a>
</p>
{% endblock %}
from django.urls import path from django.urls import path
from .views import index from .views import (
index,
AnnouncementsDetailView,
AnnouncementsCreateView,
AnnouncementsUpdateView,
)
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('<int:pk>/details/', AnnouncementsDetailView.as_view(), name='announcement-details'),
path('add/', AnnouncementsCreateView.as_view(), name='announcement-add'),
path('<int:pk>/edit/', AnnouncementsUpdateView.as_view(), name='announcement-edit'),
] ]
app_name = 'announcement_board' app_name = 'announcements'
\ No newline at end of file \ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from .models import Announcement, Reaction from django.views.generic.edit import CreateView, UpdateView
from .models import Announcement
def index(request): def index(request):
announcement_view = "Widget's Announcement Board <br/>" announcement_view = "Widget's Announcement Board <br/>"
announcements = Announcement.objects.all() announcements = Announcement.objects.all()
reactions = Reaction.objects.all() return render(
request,
'announcements/announcements.html',
{'announcements_list': announcements},
)
for a in announcements:
like_tally=0 class AnnouncementsDetailView(DetailView):
love_tally=0 model = Announcement
angry_tally=0 template_name = 'announcements/announcement-details.html'
for r in reactions:
if r.name=="Like" and r.announcement==a:
like_tally+=r.tally class AnnouncementsCreateView(CreateView):
elif r.name=="Love" and r.announcement==a: model = Announcement
love_tally+=r.tally fields = 'title', 'body', 'author'
elif r.name=="Angry" and r.announcement==a: template_name = 'announcements/announcement-add.html'
angry_tally+=r.tally
announcement_view += "<br/> {} by {} {} published {}: <br/> {} <br/> Like: {} <br/> Love: {} <br/> Angry: {} <br/>".\
format(a.title, class AnnouncementsUpdateView(UpdateView):
a.author.first_name, model = Announcement
a.author.last_name, fields = 'title', 'body', 'author'
a.pub_datetime.strftime('%m/%d/%Y, %H:%M %p'), template_name = 'announcements/announcement-edit.html'
a.body,
like_tally, # for a in announcements:
love_tally, # like_tally=0
angry_tally) # love_tally=0
# angry_tally=0
# for r in reactions:
# if r.name=="Like" and r.announcement==a:
# like_tally+=r.tally
# elif r.name=="Love" and r.announcement==a:
# love_tally+=r.tally
# elif r.name=="Angry" and r.announcement==a:
# angry_tally+=r.tally
# announcement_view += "<br/> {} by {} {} published {}: <br/> {} <br/> Like: {} <br/> Love: {} <br/> Angry: {} <br/>".\
# format(a.title,
# a.author.first_name,
# a.author.last_name,
# a.pub_datetime.strftime('%m/%d/%Y, %H:%M %p'),
# a.body,
# like_tally,
# love_tally,
# angry_tally)
return HttpResponse(announcement_view) # return HttpResponse(announcement_view)
\ No newline at end of file \ No newline at end of file
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