Commit 18a248ce authored by Emilio Gentolia's avatar Emilio Gentolia

merged branches with forum

parents 69139449 d293ac1b
......@@ -4,10 +4,10 @@ from homepage.models import WidgetUser
class Announcement(models.Model):
announcement_title = models.CharField(max_length=120)
announcement_body = models.TextField(blank=True)
pub_date = models.DateField("date published")
pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
announcement_pic = models.FileField(
upload_to="uploads", null=True, blank=True)
upload_to="media/announcement_board", null=True, blank=True)
def __str__(self):
return self.announcement_title
......
label {
font-family: Khula;
font-weight: 600;
}
input {
font-family: Khula;
}
p {
margin: 30px 0px;
}
form {
padding-bottom: 20px;
}
\ No newline at end of file
......@@ -18,3 +18,17 @@
font-size: 30px;
margin: 0
}
.new-announcement-link {
text-decoration: none;
font-family: Khula;
color: black;
font-size: 26px;
padding: 10px;
width: fit-content;
transition: 0.2s ease-in-out;
}
.new-announcement-link:hover {
background-color: rgba(0, 0, 0, 0.8);
color: white;
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}Homepage{% endblock %}
{% block title %}Announcements{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcement_board/announcement_detail.css' %}">
......@@ -13,7 +13,11 @@
{% endblock %}
{% block content %}
{% if object.announcement_pic != None and object.announcement_pic != '' %}
<img width=1000 height=200 src="{% get_media_prefix %}{{object.announcement_pic}}"/>
{% else %}
<img width=1000 height=200 src="{% static 'announcement_board/default_announcementpic.png' %}"/>
{% endif %}
<p> {{object.announcement_body}} <p>
<p> by {{object.author.first_name}} {{object.author.last_name}}, {{object.pub_date | date:"d/m/o"}}</p>
<p> Likes: {{reaction_likes}} </p>
......
<!-- announcements/announcement_form.html -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Announcements{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcement_board/announcement_form.css' %}">
{% endblock %}
{% block header %}
New Announcement
{% endblock %}
{% block content %}
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Announcement">
</form>
{% endblock %}
\ No newline at end of file
......@@ -26,4 +26,5 @@ Announcement Board
</li>
{% endfor %}
</ul>
<a class="new-announcement-link" href="add">New Announcement</a>
{% endblock %}
\ No newline at end of file
from types import NoneType
from django.shortcuts import render
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from .models import Announcement, Reaction
......@@ -16,9 +18,20 @@ class AnnouncementDetailView(DetailView):
model = Announcement
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if (Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Angry").first() != None):
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
else:
context['reaction_likes'] = 0
context['reaction_love'] = 0
context['reaction_angry'] = 0
return context
class AnnouncementCreateView(CreateView):
model = Announcement
fields = ["announcement_title", "announcement_body", "author", "announcement_pic"]
def get_success_url(self):
return "/announcements/"
......@@ -19,7 +19,7 @@ from django.conf.urls.static import static
from django.conf import settings
from homepage.views import WidgetUserCreateView
from forum.views import PostCreateView
from announcement_board.views import AnnouncementCreateView
urlpatterns = [
path('homepage/', include("homepage.urls", namespace='homepage')),
......@@ -31,6 +31,8 @@ urlpatterns = [
path('forum/', include("forum.urls", namespace='forum')),
path('announcements/', include("announcement_board.urls",
namespace='announcement_board')),
path('announcements/add', AnnouncementCreateView.as_view(),
name='announcement_form'),
path('assignments/', include("assignments.urls", namespace='assignments')),
]
......
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