Commit 592cf44e authored by Kyla Martin's avatar Kyla Martin

Merge branch 'martin/announcements' into 'master'

Martin/announcements

See merge request !14
parents 5c3b03e1 340ca903
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap');
body{
font-family: 'Roboto';
padding: 4rem 12rem;
}
h1{
font-size: 2.5rem;
text-align: center;
}
#back{
padding: 2rem 0;
}
#title{
margin: 20px 0 10px 0;
}
#subtitle{
margin: auto;
text-align: center;
}
.reactions{
background-color:gainsboro;
padding: 5px;
width: fit-content;
border-radius: 5px;
}
li{
color: black;
}
a{
color: black;
text-decoration: none;
}
a:hover{
color: red;
}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'Announcements/styles.css' %}">
{% endblock %}
{% block title %}
{{ announcement.announcement_title }}
{% endblock %}
{% block content %}
<article>
<div id="back"><a href="/announcements">Back to all announcements</a></div>
<div align="center"><img id="header" src="{% static 'Announcements/header.png' %}" alt="a header"></div>
<h1 id="title">{{ announcement.announcement_title}}</h1>
<h4 id="subtitle">by {{ announcement.author.first_name}} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"d/m/Y" }}</h4>
<p class="body">{{ announcement.announcement_body }}</p>
<div id="reactions-container" align="center">
<p class="reactions">{% for reactions in reaction_sorted %}
<strong>{{ reactions.reaction_name }}</strong>: {{ reactions.tally }}
{% endfor %}
</p>
</div>
</article>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'Announcements/styles.css' %}">
{% endblock %}
{% block title %}Widget's Announcement Board{% endblock %}
{% block content %}
<main>
<h1>Announcement Board</h1>
<h3>Important Announcements:</h3>
<ul class="announcements"></ul>
{% for announcement in announcement_sorted %}
<li> <a href="/announcements/{{ announcement.pk }}/details"><strong>{{ announcement.announcement_title }}</strong> by <strong>{{ announcement.author.first_name }} {{ announcement.author.last_name }}</strong> dated <strong>{{ announcement.pub_date|date:"d/m/Y" }}</strong></a>
</li>
{% endfor %}
</ul>
</main>
{% endblock %}
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import Http404, HttpResponse
from .models import Announcement, Reaction from .models import Announcement, Reaction
def date_month_year(timestamp): def date_month_year(timestamp):
return timestamp.strftime("%d/%m/%Y") return timestamp.strftime("%d/%m/%Y")
def index(request): def index(request):
content = "ANNOUNCEMENTS:<br>" return render(request, 'announcements/index.html', {'announcement_sorted': Announcement.objects.order_by('-pub_date')})
announcements = Announcement.objects.all()
for announcements in announcements:
content += f'{announcements.announcement_title} by {announcements.author.last_name}, {announcements.author.first_name} dated {date_month_year(announcements.pub_date)}: <br>'
content += f'{announcements.announcement_body} <br>'
reactions = announcements.reaction_set.all() def details(request, announcement_id):
for reactions in reactions: try:
content += f'{reactions.reaction_name}: {reactions.tally} <br>' announcement = Announcement.objects.get(pk=announcement_id)
except Announcement.DoesNotExist:
content +='<br>' raise Http404('Announcement does not exist')
return render (request, 'announcements/details.html', {'announcement': announcement, 'reaction_sorted': announcement.reaction_set.order_by('tally')})
return HttpResponse(content) \ No newline at end of file
\ No newline at end of file
...@@ -15,6 +15,7 @@ Including another URLconf ...@@ -15,6 +15,7 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
import Announcements.views as Announcements_views
import Forum.views as Forum_views import Forum.views as Forum_views
urlpatterns = [ urlpatterns = [
...@@ -23,5 +24,6 @@ urlpatterns = [ ...@@ -23,5 +24,6 @@ urlpatterns = [
path('posts/<int:post_id>/details/', Forum_views.details, name='post_details'), path('posts/<int:post_id>/details/', Forum_views.details, name='post_details'),
path('homepage/', include('Homepage.urls', namespace="Homepage")), path('homepage/', include('Homepage.urls', namespace="Homepage")),
path('announcements/', include('Announcements.urls', namespace="Announcements")), path('announcements/', include('Announcements.urls', namespace="Announcements")),
path('announcements/<int:announcement_id>/details', Announcements_views.details, name='announcement_details'),
path('assignments/', include('Assignments.urls', namespace="Assignments")), path('assignments/', include('Assignments.urls', namespace="Assignments")),
] ]
No preview for this file 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