Commit 819d6dba authored by Lex Philip Gabriel D. Chan's avatar Lex Philip Gabriel D. Chan

Fixed merge conflicts

parents f67a9962 374cf47b
# Generated by Django 4.1.7 on 2023-05-10 05:08
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0006_alter_reaction_announcement'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]
from django.db import models from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils import timezone
from dashboard import models as dashboard_models from dashboard import models as dashboard_models
class Announcement(models.Model): class Announcement(models.Model):
title = models.CharField(max_length=255, default="") title = models.CharField(max_length=255, default="")
body = models.TextField(default="") body = models.TextField(default="")
author = models.ForeignKey(dashboard_models.WidgetUser, on_delete=models.CASCADE) author = models.ForeignKey(dashboard_models.WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField(default=timezone.now)
def __str__(self): def __str__(self):
return '{} by {} {} published on {}: {}'.format( return '{} by {} {} published on {}, {}: {}'.format(
self.title, self.title,
self.author.first_name, self.author.first_name,
self.author.last_name, self.author.last_name,
self.pub_datetime.strftime("%m/%d/%Y %I:%M %p"), self.pub_datetime.strftime("%m/%d/%y"),
self.pub_datetime.strftime("%I:%M %p"),
self.body self.body
) )
def formatted_date(self):
return '{}'.format(self.pub_datetime.strftime("%m/%d/%y"))
def formatted_time(self):
return '{}'.format(self.pub_datetime.strftime("%I:%M %p"))
def getLikeReactions(self):
try:
return '{}'.format(Reaction.objects.get(name="Like", announcement=self).tally)
except:
return '0'
def getLoveReactions(self):
try:
return '{}'.format(Reaction.objects.get(name="Love", announcement=self).tally)
except:
return '0'
def getAngryReactions(self):
try:
return '{}'.format(Reaction.objects.get(name="Angry", announcement=self).tally)
except:
return '0'
def get_absolute_url(self):
return reverse('announcement_board:announcement-details', kwargs={'pk': self.pk})
class Reaction(models.Model): class Reaction(models.Model):
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name='reactions') announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name='reactions')
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Announcement{% endblock %}
{% block content %}
<div class="row">
<div class="col-3 text-center text-white" style="background-color:#052c65">
<br>
<br>
<img src="{% static 'announcements_icon.png'%}" class="img-fluid" width="100" height="100">
<br>
<br>
<h2>Announcements</h2>
<h4 class="display-6" style="font-size:20px">Add New Announcement</h4>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>© Jenica e-Sports</p>
</div>
<div class="col-9 text-center">
<div class="row p-5 text-center" style="background-color:#e3e4e6">
<h1 class="display-3" style="font-size:50px; color:#052c65">Add a new announcement:</h1>
</div>
<br>
<div class="row"></div>
<form method="post">
{% csrf_token %}
{% for field in form %}
<div class="row">
<div class="col-5" style="text-align:right">
<h5 class="display-3" style="font-size:25px">{{field.label}}:</h4>
</div>
<div class="col-7" style="text-align:left">
{{field}}
</div>
</div>
<br>
{% endfor %}
<input type="submit" class="btn btn-dark" value="Save New Announcement" style="background-color:#052c65">
</form>
<br><br>
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<div class="row">
<div class="col-3 text-center text-white" style="background-color:#052c65">
<br>
<br>
<img src="{% static 'announcements_icon.png'%}" class="img-fluid" width="100" height="100">
<br>
<br>
<h2>Announcements</h2>
<h4 class="display-6" style="font-size:20px">Announcement Details</h4>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>© Jenica e-Sports</p>
</div>
<div class="col-9 text-center">
<div class="row p-5 text-center" style="background-color:#e3e4e6">
<h1 class="display-3" style="font-size:55px; color:#052c65">{{ object.title }}</h1>
</div>
<br>
<div class="row">
<div class="col-5" style="text-align:right">
<h4 style="font-size:25px">Author:</h4>
<h4 style="font-size:25px">Date and Time:</h4>
</div>
<div class="col-7" style="text-align:left">
<h5 class="display-3" style="font-size:25px">{{ object.author.first_name }} {{ object.author.last_name }}</h5>
<h5 class="display-3" style="font-size:25px">{{ object.formatted_date }}, {{ object.formatted_time }}</h5>
</div>
</div>
<br>
<div class="row p-2" style="background-color:#e3e4e6">
<h5 class="display-3" style="font-size:25px">{{ object.body }}</h5>
</div>
<br>
<div class="row">
<div class="col-5" style="text-align:right">
<h4 style="font-size:25px">Like:</h4>
<h4 style="font-size:25px">Love:</h4>
<h4 style="font-size:25px">Angry:</h4>
</div>
<div class="col-7" style="text-align:left">
<h5 class="display-3" style="font-size:25px">{{ object.getLikeReactions }}</h5>
<h5 class="display-3" style="font-size:25px">{{ object.getLoveReactions }}</h5>
<h5 class="display-3" style="font-size:25px">{{ object.getAngryReactions }}</h5>
</div>
</div>
<br><br>
<button type="button" class="btn" style="background-color:#e3e4e6">
<a href="/announcements/{{object.pk}}/edit" class="link-dark">Edit Announcement</a>
</button> &nbsp; &nbsp;
<button type="button" class="btn" style="background-color:#052c65">
<a href="/announcements/" class="link-light">Back to Announcement Board</a>
</button>
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Announcement{% endblock %}
{% block content %}
<div class="row">
<div class="col-3 text-center text-white" style="background-color:#052c65">
<br>
<br>
<img src="{% static 'announcements_icon.png'%}" class="img-fluid" width="100" height="100">
<br>
<br>
<h2>Announcements</h2>
<h4 class="display-6" style="font-size:20px">Edit Announcement</h4>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>© Jenica e-Sports</p>
</div>
<div class="col-9 text-center">
<div class="row p-5 text-center" style="background-color:#e3e4e6">
<h1 class="display-3" style="font-size:50px; color:#052c65">Edit announcement:</h1>
</div>
<br>
<div class="row"></div>
<form method="post">
{% csrf_token %}
{% for field in form %}
<div class="row">
<div class="col-5" style="text-align:right">
<h5 class="display-3" style="font-size:25px">{{field.label}}:</h4>
</div>
<div class="col-7" style="text-align:left">
{{field}}
</div>
</div>
<br>
{% endfor %}
<input type="submit" class="btn btn-dark" value="Save Changes" style="background-color:#052c65">
</form>
<br><br>
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Announcement Board{% endblock %}
{% block content %}
<div class="row">
<div class="col-3 text-center text-white" style="background-color:#052c65">
<br>
<br>
<img src="{% static 'announcements_icon.png'%}" class="img-fluid" width="100" height="100">
<br>
<br>
<h2>Announcements</h2>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>© Jenica e-Sports</p>
</div>
<div class="col-9 text-center">
<div class="row p-5 text-center" style="background-color:#e3e4e6">
<h1 class="display-3"style="font-size:55px; color:#052c65">Wecome to Widget's Announcement Board!</h1>
</div>
<br>
<br>
<h5 class="display-3"style="font-size:40px; color:#052c65">Announcements:</h5>
<br>
{% for object in announcements %}
<a href="{{ object.get_absolute_url }}" class="link-dark; display-3" style="font-size:18px; color:#052c65">
{{ object.title }} by {{ object.author.first_name }} {{ object.author.last_name }}</a>
<br>
{% endfor %}
<br><br>
<button type="button" class="btn btn-dark" style="background-color:#e3e4e6">
<a href="/announcements/add" class="link-dark">New Announcement</a>
</button>
<br>
<br>
<br>
<button type="button" class="btn btn-dark" style="background-color:#052c65">
<a href="/dashboard/" class="link-light">Dashboard</a>
</button> &nbsp;
<button type="button" class="btn btn-dark" style="background-color:#334277">
<a href="/forum/" class="link-light">Forum</a>
</button> &nbsp;
<button type="button" class="btn btn-dark" style="background-color:#425086">
<a href="/assignments/" class="link-light">Assignments</a>
</button> &nbsp;
<button type="button" class="btn btn-dark" style="background-color:#515e96">
<a href="/calendar/" class="link-light">Calendar</a>
</button>
</div>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import announcements, AnnouncementDetailView, AnnouncementCreateView, AnnouncementUpdateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', announcements, name='announcements'),
path('<int:pk>/details/', AnnouncementDetailView.as_view(), name='announcement-details'),
path('add/', AnnouncementCreateView.as_view(), name='announcement-add'),
path('<int:pk>/edit/', AnnouncementUpdateView.as_view(), name='announcement-edit'),
] ]
app_name = "announcement_board" app_name = "announcement_board"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render, redirect
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement
from .models import Reaction
def index(request): from .models import Announcement, Reaction
return_string = "<p>Widget's Announcement Board</p> <p>Announcements:<br>"
for announcements in Announcement.objects.all(): def announcements(request):
announcement_string = '{} by {} {} published {}, {}:<br>{}<br>'.format( return render(request, 'announcement_board/announcements.html', {'announcements':Announcement.objects.order_by('-pub_datetime')})
announcements.title,
announcements.author.first_name,
announcements.author.last_name,
announcements.pub_datetime.strftime("%m/%d/%Y"),
announcements.pub_datetime.strftime("%I:%M %p"),
announcements.body
)
return_string += announcement_string
reactionList = announcements.reactions.all() class AnnouncementDetailView(DetailView):
sortedReactionList = sortReactions(reactionList) model = Announcement
template_name = 'announcement_board/announcement-details.html'
for reaction in sortedReactionList: class AnnouncementCreateView(CreateView):
reactions_string = '{}: {}<br>'.format( model = Announcement
reaction.name, fields = 'title', 'body', 'author'
reaction.tally template_name = 'announcement_board/announcement-add.html'
)
return_string += reactions_string
return_string += '</p>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(return_string) class AnnouncementUpdateView(UpdateView):
model = Announcement
# Sorting the reactions to Like, Love, and Angry order. fields = 'title', 'body', 'author'
def sortReactions(list): template_name = 'announcement_board/announcement-edit.html'
sortedReactionList = ['']*3 \ No newline at end of file
for reaction in list:
if reaction.name=="Like":
sortedReactionList[0] = reaction
elif reaction.name=="Love":
sortedReactionList[1] = reaction
elif reaction.name=="Angry":
sortedReactionList[2] = reaction
return sortedReactionList
\ No newline at end of file
...@@ -18,4 +18,4 @@ class WidgetUser(models.Model): ...@@ -18,4 +18,4 @@ class WidgetUser(models.Model):
return '{}, {}'.format(self.last_name, self.first_name) return '{}, {}'.format(self.last_name, self.first_name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('dashboard:widgetuser-details', kwargs={'pk': self.pk}) return reverse('dashboard:widgetuser-details', kwargs={'pk': self.pk})
\ No newline at end of file
...@@ -125,7 +125,7 @@ USE_TZ = True ...@@ -125,7 +125,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/ # https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type # Default primary key field type
......
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