Commit bed1aa58 authored by Jayson Lim's avatar Jayson Lim

created announcements.html and updated files according to renamed app

parent 2bda3412
# Generated by Django 3.2 on 2023-03-05 07:28
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcementBoard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='annoucement',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcementBoard.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=5),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.PositiveIntegerField(default=0),
),
]
# Generated by Django 3.2 on 2023-03-05 09:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcementBoard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='annoucement',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcementBoard.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=5),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.PositiveIntegerField(default=0),
),
]
# Generated by Django 3.2 on 2023-03-05 11:15
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcementBoard', '0002_auto_20230305_1528'),
('announcementBoard', '0002_auto_20230305_1746'),
]
operations = [
]
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement
from dashboard.models import WidgetUser
def index(request):
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:450%;'>\
Widget's Announcement Board\
</h1>"
body = "<h2>Announcements:</h2>"
for x in Announcement.objects.all():
reaction = x.reactions.all()
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
{} by {} {} published {}:\
<br>\
{}\
</p>".format(x.title, x.author.first_name, x.author.last_name,
x.format_pub_datetime(), x.body)
for y in reaction:
body += "<p>{}: {}\
</p>".format(y.name, y.tally)
body += '<p>&nbsp;</p>'
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
......@@ -23,9 +23,9 @@ class AnnouncementAdmin(admin.ModelAdmin):
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('name', 'tally', 'annoucement')
search_fields = ('name', 'annoucement')
list_filter = ('name', 'annoucement')
list_display = ('name', 'tally', 'announcement')
search_fields = ('name', 'announcement')
list_filter = ('name', 'announcement')
admin.site.register(Announcement, AnnouncementAdmin)
......
......@@ -3,4 +3,4 @@ from django.apps import AppConfig
class AnnouncementboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcementBoard'
name = 'announcements'
# Generated by Django 3.2 on 2023-03-04 07:17
# Generated by Django 3.2 on 2023-05-11 07:09
from django.db import migrations, models
import django.db.models.deletion
......@@ -20,16 +20,16 @@ class Migration(migrations.Migration):
('title', models.CharField(default='', max_length=250)),
('body', models.TextField(blank=True, null=True)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='dashboard.widgetuser')),
('author', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)),
('tally', models.IntegerField(default=0)),
('annoucement', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='announcementBoard.announcement')),
('name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=5)),
('tally', models.PositiveIntegerField(default=0)),
('announcement', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcements.announcement')),
],
),
]
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
class Announcement(models.Model):
......@@ -20,12 +21,15 @@ class Announcement(models.Model):
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
def get_absolute_url(self):
return reverse('announcements:announcement-detail', kwargs={'pk': self.pk})
class Reaction(models.Model):
name = models.CharField(max_length=5, choices=[('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')], default='Like')
tally = models.PositiveIntegerField(default=0)
annoucement = models.ForeignKey(
announcement = models.ForeignKey(
Announcement,
null=True,
default=True,
......
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block heading %}
<h1> {{ object.title }} </h1>
<h2> by {{ object.author.first_name }} {{ object.author.last_name }} </h2>
<h4> {{ object.format_pub_datetime }} </h4>
<p> {{ object.body }} </p>
{% for reaction in object.reactions.all %}
<p>
{{ reaction.name }}: {{ reaction.tally }}
</p>
<br>
{% endfor %}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Announcement Board {% endblock %}
{% block heading %}
<h1> Welcome to Widget's Announcement Board! </h1>
{% endblock %}
{% block content %}
<h2> Announcements: </h2>
<ul>
{% for object in announcements %}
<li>
<a href="{{ object.get_absolute_url }}"> {{ object.title }} by
{{ object.author.first_name}} {{ object.author.last_name }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import index, AnnouncementsDetailView
urlpatterns = [
path('', index, name='index'),
path('announcements/<int:pk>/details', AnnouncementsDetailView.as_view(), name='announcements-detail'),
]
app_name = "announcementBoard"
\ No newline at end of file
app_name = "announcements"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from dashboard.models import WidgetUser
def index(request):
announcements = Announcement.objects.all()
return render(request, 'announcements/announcements.html', {'announcements':announcements})
class AnnouncementsDetailView(DetailView):
model = Announcement
template_name = 'announcements/announcement-details.html'
......@@ -18,7 +18,7 @@
{% block navigation %}
<button class="buttonLink" onclick="window.location.href='add/';"> <b>New Assignment</b> </button><br><br>
<a class="miniLink" href="/dashboard"> Dashboard </a> <br>
<a class="miniLink" href="/announcementBoard"> Announcements </a> <br>
<a class="miniLink" href="/announcements"> Announcements </a> <br>
<a class="miniLink" href="/forum"> Forum </a> <br>
<a class="miniLink" href="/widget_calendar"> Calendar </a> <br>
{% endblock %}
\ No newline at end of file
......@@ -29,7 +29,7 @@
</button>
</div>
<div id="footer">
<a href="{% url 'announcementBoard:index' %}">Announcement Board</a>
<a href="{% url 'announcements:index' %}">Announcement Board</a>
<a href="{% url 'forum:index' %}">Forum</a>
<a href="{% url 'assignments:homePage' %}">Assignments</a>
<a href="{% url 'widget_calendar:index' %}">Calendar</a>
......
......@@ -21,7 +21,7 @@
<button onclick="window.location.href='{% url 'forum:forumpost-add' %}';" class="action-button"> New Post </button>
<div id="footer">
<a href="{% url 'dashboard:index' %}">Dashboard</a>
<a href="{% url 'announcementBoard:index' %}">Announcements</a>
<a href="{% url 'announcements:index' %}">Announcements</a>
<a href="{% url 'assignments:homePage' %}">Assignments</a>
<a href="{% url 'widget_calendar:index' %}">Calendar</a>
</div>
......
......@@ -43,7 +43,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'dashboard',
'assignments',
'announcementBoard',
'announcements',
'forum',
'widget_calendar',
]
......
......@@ -21,6 +21,6 @@ urlpatterns = [
path('', include('dashboard.urls', namespace="dashboard")),
path('widget_calendar/', include('widget_calendar.urls', namespace="widget_calendar")),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('announcementBoard/', include('announcementBoard.urls', namespace="announcementBoard")),
path('announcements/', include('announcements.urls', namespace="announcements")),
path('forum/', include('forum.urls', namespace="forum")),
]
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