Commit 4c40105b authored by Marco Anton O. Paeldon's avatar Marco Anton O. Paeldon

Merge remote-tracking branch 'origin/announcementsv2'

parents 2d730eb0 27e7482d
# Generated by Django 4.2.1 on 2023-05-14 10:14
import datetime
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 14, 7, 675506, tzinfo=datetime.timezone.utc), null=True),
),
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcements.announcement'),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:15
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0002_alter_announcement_pub_datetime_and_more'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 15, 20, 437714), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:16
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 16, 2, 52254, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:19
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 19, 54, 26317), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:19
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 19, 58, 681479), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:20
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 20, 10, 470392), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:20
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0007_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 20, 54, 417267, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:21
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0008_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 21, 58, 841410, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:23
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0009_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 23, 45, 514623, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:26
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0010_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(null=True, verbose_name=datetime.datetime(2023, 5, 14, 10, 26, 29, 923612, tzinfo=datetime.timezone.utc)),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:27
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0011_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 27, 0, 13958, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0012_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default='django.utils.timezone.now', null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:37
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('announcements', '0013_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=django.utils.timezone.now, null=True),
),
]
from django.db import models from django.db import models
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
from django.urls import reverse
import django
class Announcement(models.Model): class Announcement(models.Model):
title = models.CharField(max_length=255, null=True) title = models.CharField(max_length=255, null=True)
body = models.TextField(null=True) body = models.TextField(null=True)
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True) author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(null=True) pub_datetime = models.DateTimeField(default = django.utils.timezone.now, null=True)
def __str__(self): def __str__(self):
return f"{self.title}" return f"{self.title}"
...@@ -14,7 +16,7 @@ class Announcement(models.Model): ...@@ -14,7 +16,7 @@ class Announcement(models.Model):
class Reaction(models.Model): class Reaction(models.Model):
name = models.CharField(max_length=255, null=True) name = models.CharField(max_length=255, null=True)
tally = models.IntegerField(null=True) tally = models.IntegerField(null=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True) announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True, related_name='reactions')
def __str__(self): def __str__(self):
return f"{self.name}" return f"{self.name}"
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add Announcement{% endblock %}
{% block content %}
<h1>Add a new announcement:</h1>
<form method="POST" enctype="multipart/form-data">
<!-- Security token -->
{% csrf_token %}
<!-- Using the formset -->
{{ form.as_p }}
<input type="submit" value="Add Announcement">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} {{myannouncement.title}} {% endblock %}
{% block content %}
<h1>{{ myannouncement.title }}</h1>
<p><b> by {{ myannouncement.author.first_name }} {{ myannouncement.author.last_name }}</b></p>
<p><b>{{ myannouncement.pub_datetime | date:"m/d/Y, h:i A" }}</p>
<p><b>{{ myannouncement.body }}</p>
<ul>
{% for x in reactions %}
<li>{{ x.name }} {{ x.tally }}</li>
{% endfor %}
</ul>
<form action='edit' method="get" enctype="multipart/form-data">
{% csrf_token %}
<input type="submit" value="Edit Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Edit Announcement{% endblock %}
{% block content %}
<h1>Edit announcement:</h1>
<form method="post" enctype="multipart/form-data">
<!-- Security token -->
{% csrf_token %}
<!-- Using the formset -->
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Announcements{% endblock %}
{% block content %}
<h1>Welcome to Widget's Announcements!</h1>
{%for object in announcements%}
<a href="{{ object.pk }}/details">{{ object.title }} by {{ object.author.first_name }} {{ object.author.last_name }}</a>
<br>
{%endfor%}
<form action="/announcements/add" method="get" enctype="multipart/form-data">
{% csrf_token %}
<input type="submit" value="New Announcement">
</form>
<br>
<a href="/dashboard">Dashboard</a>
<br>
<a href="/assignments">Assignments</a>
<br>
<a href="/forum">Forum</a>
<br>
<a href="/calendar">Calendar</a>
<br>
{% endblock %}
from django.urls import path from django.urls import path
from .views import index from .views import announcements_view, AnnouncementsDetailView, AnnouncementsCreateView, AnnouncementsUpdateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', announcements_view, name='announcements_page'),
path('<int:pk>/details/', AnnouncementsDetailView.as_view(), name='announcements-details'),
path('add', AnnouncementsCreateView.as_view(), name='announcements-add'),
path('<int:pk>/details/edit', AnnouncementsUpdateView.as_view(), name='announcements-edit'),
] ]
app_name = "announcements" app_name = "announcements"
\ No newline at end of file
...@@ -2,6 +2,9 @@ from django.shortcuts import render ...@@ -2,6 +2,9 @@ from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement, Reaction from .models import Announcement, Reaction
import datetime import datetime
from django.views.generic import CreateView, UpdateView
from django.views.generic.detail import DetailView
from django.urls import reverse
def index(request): def index(request):
overall_board = "<html><title>Announcement Board</title><body>" \ overall_board = "<html><title>Announcement Board</title><body>" \
...@@ -21,3 +24,40 @@ def index(request): ...@@ -21,3 +24,40 @@ def index(request):
overall_board += "</body></html>" overall_board += "</body></html>"
return HttpResponse(overall_board) return HttpResponse(overall_board)
def announcements_view(request):
announcements = Announcement.objects.all().order_by('-pub_datetime')
return render(request, 'announcements/announcements.html', {'announcements': announcements})
class AnnouncementsDetailView(DetailView):
def get(self, request, pk):
myannouncement = Announcement.objects.get(pk=pk)
reactions = myannouncement.reactions.all().values()
context = {
'myannouncement': myannouncement,
'reactions': reactions,
}
return render(request, 'announcements/announcement-details.html', context)
class AnnouncementsCreateView(CreateView):
model = Announcement
fields = ["title", "body", "author"]
template_name = 'announcements/announcement-add.html'
def get_success_url(self):
return reverse('announcements:announcements-details', kwargs={'pk': self.object.pk})
class AnnouncementsUpdateView(UpdateView):
model = Announcement
fields = ["title", "body", "author"]
template_name = 'announcements/announcement-edit.html'
def get_success_url(self):
return reverse('announcements:announcements-details', kwargs={'pk': self.object.pk})
<!-- bookshelf/template/base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}{% endblock %}</title>
</head>
<body style = "background-color:#F0FFFF;">
{% block header %}
{% endblock %}
<br>
{% block content %}
{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
...@@ -10,3 +10,4 @@ ...@@ -10,3 +10,4 @@
</div> </div>
</body> </body>
</html> </html>
...@@ -10,7 +10,6 @@ For the full list of settings and their values, see ...@@ -10,7 +10,6 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/ https://docs.djangoproject.com/en/4.1/ref/settings/
""" """
import os
from pathlib import Path from pathlib import Path
import os import os
......
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