edited and finalized announcement board

parent 86b4a25f
# Generated by Django 4.0.3 on 2022-05-22 15:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_alter_announcement_pub_date'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='images',
field=models.ImageField(default='default.jpg', upload_to='announcement'),
),
]
......@@ -7,10 +7,11 @@ class Announcement(models.Model):
announcement_title = models.CharField(max_length=50)
announcement_body = models.CharField(max_length=500)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE,default = 1)
images = models.ImageField (upload_to="announcement", default = "default.jpg")
pub_date = models.DateField("Date Published")
def __str__(self):
return self.announcement_title
return f"{self.announcement_title} {self.announcement_body} {self.pub_date}"
class Reaction(models.Model):
reaction_name = models.CharField(max_length=10)
......@@ -18,4 +19,4 @@ class Reaction(models.Model):
announcement = models.ForeignKey(Announcement,on_delete=models.CASCADE, default = 1)
def __str__(self):
return self.reaction_name
\ No newline at end of file
return f"{self.reaction_name} {self.tally}"
\ No newline at end of file
h1 {
text-align: center;
color:rgb(90, 90, 90);
text-shadow:2px 2px 5px rgb(200, 15, 100);
font-family: "Lucida Grande";
font-size: 75px;
}
h2 {
color:rgb(216, 94, 216);
font-size: 20px;
font-family: "Helvetica";
}
body {
background-color: rgb(255, 255, 255);
}
p {
color:rgb(0, 180, 216);
font-size: 25px;
font-family: "Arial Narrow";
}
a {
color:rgb(5, 119, 100);
font-size: 22px;
font-family: "Arial Narrow";
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
\ 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>{% block title %}It is a Page LOL{% endblock %}</title>
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block title %}announcement details{% endblock %}
{%block content%}
<h1>{{ announcement.announcement_title }}</h1>
<h2>by {{ announcement.author }}, {{announcement.pub_date}}</h2>
<p>{{announcement.announcement_body}}</p>
<ul>
{% for reaction in reactionList %}
<li>{{ reaction.reaction_name }}: {{reaction.tally}}</a></li>
{% endfor %}
</ul>
<br /><br /><br /><img src="{{ announcement.images.url }}" alt="{{announcement.announcement_title}}" style="width:50%">
{% endblock %}
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block title %}Announcements{% endblock %}
{% block content %}
<h1>Announcement Board</h1>
<p>Important Announcements</p>
{% if announcementList %}
<ul>
{% for announcement in announcementList %}
<li><a href="{{ announcement.id }}/details/">{{announcement.announcement_title}} by {{ announcement.author }} dated {{ announcement.pub_date }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No users are available</p>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -3,5 +3,9 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='announcementboardIndex')
path('', views.index, name='announcementboardIndex'),
# announcement/1/details
path("<int:announcement_id>/details/", views.details, name="details")
]
app_name = "announcement"
\ 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
text = ""
announcementCounter = 1
reactionCounter = 0
announcementList = Announcement.objects.all()
announcementList = Announcement.objects.order_by("pub_date")
reactionList = Reaction.objects.all()
outputText = "ANNOUNCEMENTS:"
for i in announcementList:
text += "<br />" + f"{i.announcement_title} by " + f"{i.author} dated " + f"{i.pub_date}:<br />" + f"{i.announcement_body}<br />"
if announcementCounter == 1:
while reactionCounter < 3:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
elif announcementCounter == 2:
while reactionCounter < 6:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
elif announcementCounter == 3:
while reactionCounter < 9:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
announcementCounter += 1
outputText += text
# Create your views here.
def index(request):
return HttpResponse(outputText)
\ No newline at end of file
context = {
"announcementList": announcementList,
}
return render(request, "announcements/index.html", context)
def details(request, announcement_id):
try:
announcement = Announcement.objects.get(pk=announcement_id)
except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!")
for reaction in announcementList:
if reaction.id == announcement_id:
announcement = reaction
break
context = {
"announcement": announcement,
"announcement_id": announcement_id
}
return render(request, "announcements/details.html", context)
\ No newline at end of file
......@@ -6,8 +6,8 @@
<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" href="{% static 'homepage/style.css' %}">
<title>{% block title %}Woah a page{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
<title>{% block title %}Oh look, a page{% endblock %}</title>
</head>
<body>
<div id="content">
......
{% extends 'base.html' %}
{% load static %}
{% extends 'assignments/base.html' %}
{% block title %}Assignment no. {{ assignment_id }}{% endblock %}
......
{% extends 'base.html' %}
{% load static %}
{% extends 'assignments/base.html' %}
{% block title %}Assignments{% endblock %}
......
h1 {
text-align: center;
color:rgb(122, 124, 240);
text-shadow:2px 2px 5px rgb(101, 15, 158);
font-family: "Brush Script MT", "Brush Script Std";
font-size: 50px;
}
h2 {
color:rgb(8, 28, 54);
font-size: 20px;
font-family: "Arial Narrow", sans-serif;
}
body {
background-color: rgb(163, 163, 163);
}
p {
color:rgb(0, 0, 0);
font-size: 25px;
font-family: "New Century Schoolbook", "TeX Gyre Schola", serif;
}
a {
color:rgb(133, 0, 77);
font-size: 20px;
font-family: "Arial Narrow", sans-serif;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
\ No newline at end of file
......@@ -6,8 +6,8 @@
<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" href="{% static 'assignments/style.css' %}">
<title>{% block title %}Woah a page{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'forum/style.css' %}">
<title>{% block title %}What a page{% endblock %}</title>
</head>
<body>
<div id="content">
......
{% extends 'base.html' %}
{% load static %}
{% extends 'forum/base.html' %}
{% block title %}post details{% endblock %}
......
{%extends 'base.html'%}
{%load static%}
{% extends 'forum/base.html' %}
{%block title%}Forum{%endblock%}
......
......@@ -6,8 +6,8 @@
<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" href="{% static 'forum/style.css' %}">
<title>{% block title %}Wahoo{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'homepage/style.css' %}">
<title>{% block title %}Woah, a page{% endblock %}</title>
</head>
<body>
<div id="content">
......
{% extends 'base.html' %}
{% load static %}
{% extends 'homepage/base.html' %}
{% block title %}User no. {{ user_id }}{% endblock %}
......
{% extends 'base.html' %}
{% load static %}
{% extends 'homepage/base.html' %}
{% block title %}Homepage{% endblock %}
......
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