Commit cbc44952 authored by Maso Crisostomo's avatar Maso Crisostomo

Updated templates of announcements and fixed forum pub_date

parent 538d60f3
h1 {
color: white;
color: darkred;
font-weight: bold;
}
h4 {
color: darkred;
font-weight: bold;
}
p {
color: white;
color: black;
font-weight: normal;
}
body {
background-color: black;
background-color: lightsteelblue;
}
a {
......
......@@ -7,7 +7,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'announcements/style.css' %}">
<title>My Blog Site</title>
<!-- <title>Announcement Board</title> -->
</head>
<body>
<!-- <script src="index.js"></script> -->
......
{% extends "announcements/base.html" %}
{% block content %}
<h1> {{ announcement.announcement_title }} </h1>
<p> {{ announcement.announcement_body }} </p>
{% endblock %}
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block content %}
<h1> {{ announcement.announcement_title }} </h1>
<h4>by {{ announcement.author.first_name }} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"SHORT_DATE_FORMAT" }}</h4>
<p> {{ announcement.announcement_body }} </p>
{% if reaction_list %}
<ul>
{% for r in reaction_list %}
<li>{{ r.reaction_name }}: {{ r.tally }}</li>
{% endfor %}
</ul>
{% else %}
<p>No posts are available.</p>
{% endif %}
{% load static %}
<img src="{% static image_url %}" alt="Photo of Post"/>
{% endblock %}
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block content %}
<h1>Announcement Board</h1>
{% if announcements_list %}
<ul>
{% for announcement in announcements_list %}
<li><a href="{% url 'announcements:detail' announcement.id %}">{{ announcement.announcement_title }}</a></li>
{% for a in announcements_list %}
<li><a href="{% url 'announcements:details' a.id %}">{{ a.announcement_title }} by {{ a.author.first_name }} {{ a.author.last_name }} dated {{ a.pub_date|date:"SHORT_DATE_FORMAT" }}</a></li>
{% endfor %}
</ul>
{% else %}
......
......@@ -5,10 +5,11 @@ from . import views
app_name = "announcements"
urlpatterns = [
path('', views.index, name='index'),
#announcements/1
path("<int:announcement_id>", views.detail, name="detail"),
#announcements/1/details
path("<int:announcement_id>/details", views.details, name="details"),
#announcements/1/reactions
path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
# path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
#announcements/1/react
path("<int:announcement_id>/react", views.react, name="react")
# path("<int:announcement_id>/react", views.react, name="react")
]
\ No newline at end of file
......@@ -5,12 +5,35 @@ from .models import Announcement, Reaction
# Create your views here.
def index(request):
announcements_list = Announcement.objects.order_by("pub_date")
announcements_list = Announcement.objects.order_by("-pub_date")
context = {"announcements_list": announcements_list}
return render(request, "announcements/index.html", context)
def details(request, announcement_id):
try:
announcement = Announcement.objects.get(pk=announcement_id)
reaction_list = Reaction.objects.filter(announcement=announcement)
image_url = f'announcements/{announcement.id}.png'
context = {
"announcements_list": announcements_list
"announcement": announcement,
"reaction_list": reaction_list,
"image_url": image_url
}
return render(request, "announcements/index.html", context)
except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!")
return render(request, "announcements/details.html", context)
# def reactions(request, announcement_id):
# response = "This are the reactions to announcement # %s."
# return HttpResponse(response % announcement_id)
# def react(request, announcement_id):
# return HttpResponse("You are reacting to announcement # %s." % announcement_id)
# this belongs in index
# announcements_list = Announcement.objects.order_by("pub_date")
# output = ", ".join([a.announcement_title for a in announcements_list])
# return HttpResponse(output)
......@@ -28,17 +51,3 @@ def index(request):
# content += '<br/>'
# return HttpResponse(content)
\ No newline at end of file
def detail(request, announcement_id):
try:
announcement = Announcement.objects.get(pk=announcement_id)
except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!")
return render(request, "announcements/detail.html", {"announcement": announcement})
def reactions(request, announcement_id):
response = "This are the reactions to announcement # %s."
return HttpResponse(response % announcement_id)
def react(request, announcement_id):
return HttpResponse("You are reacting to announcement # %s." % announcement_id)
\ No newline at end of file
......@@ -5,7 +5,7 @@ from django.views import View
from .models import Post, Reply
def forumView(request):
posts_list = Post.objects.order_by("pub_date")
posts_list = Post.objects.order_by("-pub_date")
context = {
"posts_list": posts_list
}
......@@ -14,7 +14,7 @@ def forumView(request):
def postDetailsView(request, post_id):
displayed_post = Post.objects.get(pk=post_id)
replies_list = Reply.objects.filter(post=displayed_post).order_by("pub_date")
replies_list = Reply.objects.filter(post=displayed_post).order_by("-pub_date")
image_url = f'forum/{displayed_post.id}.png'
context = {
"post": displayed_post,
......
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