Commit a939c3d1 authored by Raul Jarod Conanan's avatar Raul Jarod Conanan

Merge branch '3-Announcementsv2' into 'dev'

3 announcementsv2

See merge request !21
parents 7811df17 3fc18139
# Generated by Django 3.2 on 2023-05-13 14:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='react', to='announcements.announcement'),
),
]
...@@ -19,6 +19,6 @@ class Reaction(models.Model): ...@@ -19,6 +19,6 @@ class Reaction(models.Model):
name = models.CharField(max_length=5, default=LIKE, null=True, blank=True) name = models.CharField(max_length=5, default=LIKE, null=True, blank=True)
tally = models.IntegerField(default=0 ,null=True, blank=True) tally = models.IntegerField(default=0 ,null=True, blank=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True) announcement = models.ForeignKey(Announcement, related_name="react", on_delete=models.CASCADE, null=True)
# Create your models here. # Create your models here.
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Add Announcement</title>
<h1>Add a new announcement:</h1>
<form action="" method=POST>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Announcement">
</form>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>{{ announce.title }}</title>
<h1>{{ announce.title }}</h1>
<h2>by {{ announce.author.first_name }} {{ announce.author.last_name }}</h2>
<p>{{ announce.pub_datetime|date:'m/d/Y, h:i A' }}</p>
<p>{{ announce.body }}</p>
<p>
{% for react in announce.react.all %}
{{ react.name }}: {{ react.tally }}<br>
{% endfor %}
</p>
<a href = "/announcements/{{ announce.pk }}/edit/"><button value="">Edit Announcement</button></a>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<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 %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Widget's Announcement Board</title>
<h1>Welcome to Widget's Announcement Board!</h1>
<h3>Announcements:</h3>
{% for announce in announcement %}
<a href = "{{ announce.pk }}/details/">{{ announce.title }} by {{ announce.author.first_name }} {{ announce.author.last_name }}</a><br>
{% endfor %} <br>
<a href="add/"><button value="click here">Add Announcement</button></a><br><br>
<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 %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import index, AnnouncementDetailView, AnnouncementAddView, AnnouncementEditView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('announcements/', index, name='index'),
path('announcements/<int:pk>/details/', AnnouncementDetailView.as_view(), name='announcementdetailview'),
path('announcements/add/', AnnouncementAddView.as_view(), name='announcement-add'),
path('announcements/<int:pk>/edit/', AnnouncementEditView.as_view(), name='announcement-edit'),
] ]
app_name = "announcements" app_name = "announcements"
\ 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 django.views.generic.edit import CreateView, UpdateView
from django.urls import reverse
from .models import Announcement, Reaction from .models import Announcement, Reaction
import pytz import pytz
from django.utils import timezone 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-details.html'
convert_to_localtime(announced.pub_datetime), announced.body) queryset = Announcement.objects.all()
for reacts in announced.reaction_set.all(): context_object_name = 'announce'
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 = ['title', 'body', 'author']
template_name = 'announcements/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.html'
fields = ['title', 'body', 'author']
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.
SECRET_KEY = 'django-insecure-t*s#_++5=ze%3#*ns6vcmt8a5bw6249en-!ek7*#3=p-dkhl_f'
\ No newline at end of file
...@@ -18,7 +18,7 @@ from django.urls import include, path ...@@ -18,7 +18,7 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('announcements/', include('announcements.urls', namespace="announcements")), path('', include('announcements.urls', namespace="announcements")),
path('widget_Calendar/', include('widget_Calendar.urls', namespace="widget_Calendar")), path('widget_Calendar/', include('widget_Calendar.urls', namespace="widget_Calendar")),
path('', include('Dashboard.urls', namespace="Dashboard")), path('', include('Dashboard.urls', namespace="Dashboard")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
......
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