Commit b67dc1ad authored by Maso Crisostomo's avatar Maso Crisostomo

Updated announcements app with templates

parent a93908a9
h1 {
color: white;
font-weight: bold;
}
p {
color: white;
font-weight: normal;
}
body {
background-color: black;
}
a {
color: orangered;
}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<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>
</head>
<body>
<!-- <script src="index.js"></script> -->
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% 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 %}
{% if announcements_list %}
<ul>
{% for announcement in announcements_list %}
<li><a href="{% url 'announcements:detail' announcement.id %}">{{ announcement.announcement_title }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No announcements are available.</p>
{% endif %}
{% endblock %}
...@@ -2,6 +2,13 @@ from django.urls import path ...@@ -2,6 +2,13 @@ from django.urls import path
from . import views from . import views
app_name = "announcements"
urlpatterns = [ urlpatterns = [
path('', views.index, name='index') path('', views.index, name='index'),
#announcements/1
path("<int:announcement_id>", views.detail, name="detail"),
#announcements/1/reactions
path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
#announcements/1/react
path("<int:announcement_id>/react", views.react, name="react")
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import render
from .models import Announcement, Reaction from .models import Announcement, Reaction
# Create your views here. # Create your views here.
def index(request): def index(request):
announcements_list = Announcement.objects.order_by("pub_date")
context = {
"announcements_list": announcements_list
}
return render(request, "announcements/index.html", context)
content = 'ANNOUNCEMENTS:<br/>' # announcements_list = Announcement.objects.order_by("pub_date")
# output = ", ".join([a.announcement_title for a in announcements_list])
announcements = Announcement.objects.all() # return HttpResponse(output)
reacts = Reaction.objects.all()
# content = 'ANNOUNCEMENTS:<br/>'
for i in announcements: # announcements = Announcement.objects.all()
announcement_date = i.pub_date.date().strftime("%m/%d/%Y") # reacts = Reaction.objects.all()
content += f'{i.announcement_title} by {i.author.first_name} {i.author.last_name} dated {announcement_date}:<br/>{i.announcement_body}<br/>'
for j in reacts: # for i in announcements:
if j.announcement == i: # announcement_date = i.pub_date.date().strftime("%m/%d/%Y")
content += f'{j.reaction_name}: {j.tally}<br/>' # content += f'{i.announcement_title} by {i.author.first_name} {i.author.last_name} dated {announcement_date}:<br/>{i.announcement_body}<br/>'
content += '<br/>' # for j in reacts:
# if j.announcement == i:
return HttpResponse(content) # content += f'{j.reaction_name}: {j.tally}<br/>'
# content += '<br/>'
# Display all available Announcements and their respective Reactions in the format # return HttpResponse(content)
# <announcement_title> by <author’s first_name> <author’s last_name> dated <pub_date>:
# announcement_body def detail(request, announcement_id):
# Like: <count> try:
# Love: <count> announcement = Announcement.objects.get(pk=announcement_id)
# Angry: <count> except Announcement.DoesNotExist:
# with the heading “ANNOUNCEMENTS: ”. An empty line separates the announcements raise Http404("Announcement does not exist!")
# from each other. return render(request, "announcements/detail.html", {"announcement": announcement})
# ■ Example:
# ANNOUNCEMENTS:
# No Synch Session by Alice Wonderland dated 03/16/2022:
# There will be no synch session next week.
# Like: 3
# Love: 5
# Angry: 0 # def reactions(request, announcement_id):
# Project Deadline by Little Luly dated 03/16/2022 # response = "This are the reactions to announcement # %s."
# Deadline for the project is next month. # return HttpResponse(response % announcement_id)
# Like: 4
# Love: 6 # def react(request, announcement_id):
# Angry: 3 # return HttpResponse("You are reacting to announcement # %s." % announcement_id)
\ No newline at end of file \ No newline at end of file
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