Commit d293ac1b authored by Emilio Gentolia's avatar Emilio Gentolia

fixed image and urls for announcements

parent 11952712
...@@ -4,10 +4,10 @@ from homepage.models import WidgetUser ...@@ -4,10 +4,10 @@ from homepage.models import WidgetUser
class Announcement(models.Model): class Announcement(models.Model):
announcement_title = models.CharField(max_length=120) announcement_title = models.CharField(max_length=120)
announcement_body = models.TextField(blank=True) 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) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
announcement_pic = models.FileField( announcement_pic = models.FileField(
upload_to="uploads", null=True, blank=True) upload_to="media/announcement_board", null=True, blank=True)
def __str__(self): def __str__(self):
return self.announcement_title return self.announcement_title
......
...@@ -17,4 +17,18 @@ ...@@ -17,4 +17,18 @@
font-family: Khula; font-family: Khula;
font-size: 30px; font-size: 30px;
margin: 0 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
...@@ -13,7 +13,11 @@ ...@@ -13,7 +13,11 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<img width=1000 height=200 src="{% static 'announcement_board/default_announcementpic.png' %}"/> {% 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> {{object.announcement_body}} <p>
<p> by {{object.author.first_name}} {{object.author.last_name}}, {{object.pub_date | date:"d/m/o"}}</p> <p> by {{object.author.first_name}} {{object.author.last_name}}, {{object.pub_date | date:"d/m/o"}}</p>
<p> Likes: {{reaction_likes}} </p> <p> Likes: {{reaction_likes}} </p>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% block title %}Announcements{% endblock %} {% block title %}Announcements{% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'announcements/announcement_form.css' %}"> <link rel="stylesheet" href="{% static 'announcement_board/announcement_form.css' %}">
{% endblock %} {% endblock %}
{% block header %} {% block header %}
......
...@@ -26,5 +26,5 @@ Announcement Board ...@@ -26,5 +26,5 @@ Announcement Board
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<a class="new-user-link" href="/announcements/add">New Announcement</a> <a class="new-announcement-link" href="add">New Announcement</a>
{% endblock %} {% endblock %}
\ No newline at end of file
from types import NoneType
from django.shortcuts import render from django.shortcuts import render
from django.views import View from django.views import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
...@@ -17,10 +18,14 @@ class AnnouncementDetailView(DetailView): ...@@ -17,10 +18,14 @@ class AnnouncementDetailView(DetailView):
model = Announcement model = Announcement
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['reaction_likes'] = Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Like").first().tally if (Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Angry").first() != None):
context['reaction_love'] = Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Love").first().tally context['reaction_likes'] = Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Like").first().tally
context['reaction_angry'] = Reaction.objects.filter(announcement_id=self.kwargs['pk']).filter(reaction_name="Angry").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 return context
class AnnouncementCreateView(CreateView): class AnnouncementCreateView(CreateView):
......
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