Commit 46418afc authored by Alia Lawraine Olay's avatar Alia Lawraine Olay

Merge branch 'olay/announcementboard'

parents a232baf8 60652b06
......@@ -13,21 +13,25 @@ class Announcement(models.Model):
def __str__(self):
return '"{}" published {}'.format(self.announcement_title, self.pub_date)
class Reaction(models.Model):
announcement = models.ForeignKey(
Announcement,
on_delete=models.CASCADE,
related_name='reactions'
)
LIKE = 'Like'
LOVE = 'Love'
ANGRY = 'Angry'
REACTION_CHOICES = [
('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')
(LIKE, 'Like'),
(LOVE, 'Love'),
(ANGRY, 'Angry')
]
reaction_name = models.CharField(
max_length=5,
choices=REACTION_CHOICES,
default='Like'
default=LIKE
)
tally = models.IntegerField(default=1, editable=False)
......
from django.urls import path
from .views import index
from .views import announcement_list_view, announcement_detail_view
urlpatterns = [
path('', index, name='index')
# path('', index, name='index')
path('', announcement_list_view, name='announcement-list'),
path('<int:pk>/details', announcement_detail_view, name='announcement-detail'),
]
app_name = "announcementboard"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Announcement
def index(request):
heading = 'ANNOUNCEMENTS:<br>'
all_announcements = Announcement.objects.all()
body = ''
for announcement in all_announcements:
count_like = announcement.reactions.filter(reaction_name='Like').count()
count_love = announcement.reactions.filter(reaction_name='Love').count()
count_angry = announcement.reactions.filter(reaction_name='Angry').count()
body += '{} by {} {} dated {}:<br>{}<br>Like: {}<br>Love: {}<br>Angry: {}<br><br>'.format(
announcement.announcement_title, announcement.author.first_name,
announcement.author.last_name, announcement.pub_date,
announcement.announcement_body, count_like,
count_love, count_angry
)
return HttpResponse(heading + body)
\ No newline at end of file
def announcement_list_view(request):
context = {}
context['object_list'] = Announcement.objects.order_by('-pub_date').all()
return render(request, 'announcementboard/announcement_list.html', context)
def announcement_detail_view(request, pk):
announcement = Announcement.objects.get(pk=pk)
context = {'announcement': announcement,
'count_like': announcement.reactions.filter(reaction_name='Like').count(),
'count_love': announcement.reactions.filter(reaction_name='Love').count(),
'count_angry': announcement.reactions.filter(reaction_name='Angry').count()
}
return render(request, 'announcementboard/announcement_detail.html', context)
\ No newline at end of file
......@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_group_25.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['widget_group_25/widget_group_25/templates'],
'DIRS': [os.path.join(BASE_DIR, 'widget_group_25/templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -123,10 +123,8 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'widget_group_25/static'),
)
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'widget_group_25/static')]
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
......
h1 {
color: #393d3f;
font-family: 'Tahoma';
font-size: 35pt;
line-height: 10px;
}
h2 {
color: #546a7b;
font-family: 'Tahoma';
font-size: 20pt;
}
h3 {
color: #546a7b;
font-family: 'Trebuchet MS';
font-size: 16pt;
font-style: italic;
}
body {
color: #393d3f;
font-family: 'Trebuchet MS';
font-size: 12pt;
line-height: 15px;
}
img {
height: 2cm;
}
\ No newline at end of file
h1 {
color: #22223b;
font-family: 'Tahoma';
font-size: 38pt;
}
h3 {
color: #4a4e69;
font-family: 'Trebuchet MS';
font-size: 18pt;
}
body {
color: #4a4e69;
font-family: 'Trebuchet MS';
font-size: 12pt;
}
a:visited {
color: #723d46;
}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ announcement.announcement_title }}{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcementboard/css/detail_styles.css' %}">
{% endblock %}
{% block content %}
{% if announcement.id == 1 or announcement.id == 4 %}
<img src="{% static 'announcementboard/css/quiz.png' %}" alt="quiz">
{% endif %}
{% if announcement.id == 2 %}
<img src="{% static 'announcementboard/css/laptop.png' %}" alt="synch">
{% endif %}
{% if announcement.id == 3 %}
<img src="{% static 'announcementboard/css/project.png' %}" alt="project">
{% endif %}
<h1>{{ announcement.announcement_title }}</h1>
<h2>
by {{ announcement.author.first_name }} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:'d/m/Y' }}
</h2>
{{ announcement.announcement_body }}
<h3>Reactions:</h3>
Like: {{ count_like }}<br>
Love: {{ count_love }}<br>
Angry: {{ count_angry }}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Announcement Board{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcementboard/css/list_styles.css' %}">
{% endblock %}
{% block content %}
<h1>Announcement Board</h1>
<h3>Important announcements:</h3>
{% for object in object_list %}
<li>
<a href="{% url 'announcementboard:announcement-detail' pk=object.pk %}">
{{ object.announcement_title }} by {{ object.author.first_name }} {{ object.author.last_name }} dated {{ object.pub_date|date:"d/m/Y" }}
</a>
</li>
{% endfor %}
{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{% block title %}BASE HTML{% endblock %}</title>
<link rel="stylesheet" href="styles.css">
<title>{% block title %}{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
......
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