Commit 10b13887 authored by Emilio Gentolia's avatar Emilio Gentolia

Created detail and index template for announcements.

parent 5d13d77d
<!-- announcements/announcement_detail.html -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Homepage{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcement_board/widgetuser_details.css' %}">
{% endblock %}
{% block header %}
<img width="50" height="50" src=""/>
{{object.announcement_title}}
{% endblock %}
{% block content %}
<p> by {{object.author.first_name}} {{object.author.last_name}}, {{object.pub_date | date:"d/m/o"}}</p>
<p> Likes: {{reaction_likes}} </p>
<p> Love: {{reaction_love}} </p>
<p> Angry: {{reaction_angry}} </p>
{% endblock %}
\ No newline at end of file
<!-- announcements/index.html -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Announcements{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcements/announcement_index.css' %}">
{% endblock %}
{% block header %}
Announcement Board
{% endblock %}
{% block content %}
<p>Important announcements:</p>
<ul>
{% for announcement in all_announcements %}
<li>
<a class="details" href="{{announcement.id}}/details">
{{announcement.announcement_title}} by
{{announcement.author.first_name}},
{{announcement.author.last_name}} dated
{{announcement.pub_date | date:"d/m/o"}}
</a> </br>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import AnnouncementView, AnnouncementDetailView
urlpatterns = [
path('', index, name='index'),
path('', AnnouncementView.as_view(), name='index'),
path('<int:pk>/details',AnnouncementDetailView.as_view(), name='announcement_detail')
]
app_name = "announcement_board"
\ No newline at end of file
from django.shortcuts import render
from django.views import View
from django.views.generic.detail import DetailView
from .models import Announcement
from .models import Announcement, Reaction
class AnnouncementView(View):
def get(self, request):
objects_set = {
"all_announcements": [obj for obj in Announcement.objects.all().order_by('last_name')]
"all_announcements": [obj for obj in Announcement.objects.all().order_by('-pub_date')]
}
return render(request, 'homepage/index.html', objects_set)
return render(request, 'announcement_board/index.html', objects_set)
class AnnouncementDetailView(DetailView):
model = Announcement
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['reaction_likes'] = Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Like").first().tally
context['reaction_love'] = Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Love").first().tally
context['reaction_angry'] = Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Angry").first().tally
return context
......@@ -17,7 +17,7 @@
nav:focus {
outline:0 !important;
}
ul {
.ul-links {
list-style-type: none;
margin: 0;
padding: 0;
......@@ -26,7 +26,7 @@ ul {
width: 100%;
background-color: #bb00ff;
}
ul li {
.ul-links li {
padding: 20px;
}
.links {
......
......@@ -9,7 +9,7 @@
</head>
<body>
<nav>
<ul>
<ul class="ul-links">
<li><a class="links" href="/homepage/">HOMEPAGE</a></li>
<li><a class="links" href="/assignments/">ASSIGNMENTS</a></li>
<li><a class="links" href="/forum/">FORUM</a></li>
......
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