Commit 838646ed authored by Julliana Zarah C. Cruz's avatar Julliana Zarah C. Cruz

Made changes for Final project and merged

parents b1718512 aae85b93
from django import forms
from .models import Announcement, Reaction
class AddAnnouncementForm(forms.ModelForm):
class Meta:
model = Announcement
fields = '__all__'
h1 {
font-family: verdana;
color: Maroon;
}
body {
font-family: verdana;
background-color: hotpink;
background-color: MistyRose;
color: SaddleBrown;
}
\ No newline at end of file
{% extends "announcements/base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% endblock %}
{% block content %}
<h1>New Announcement</h1>
<form action="{% url 'announcements:addAnnouncement' %}" method="POST">
{% csrf_token %}
{{ add_announcement }}
<p><button class="button" type="submit">Save Announcement</button></p>
</form>
<br>
<p1>
<a href = "/announcements/">Back to Announcement Page</a>
</p1>
{% endblock %}
\ No newline at end of file
......@@ -22,6 +22,10 @@
</p>
{% endfor %}
</ol>
<form action="/announcements/add">
<input type="submit" value="New Announcement" />
</form>
</body>
{% endblock %}
{% extends "announcements/base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% endblock %}
{% block content %}
<h1>
{{announcement_details.announcement_title}}
</h1>
<h2>
<h4>
by
{{announcement_details.author.first_name}}
{{announcement_details.author.last_name}}
dated {{announcement_details.pub_date|date:"d/m/Y"}}
</h2>
<p>
</h4>
<p style="border:PaleVioletRed; border-width:5px; border-style:dotted; border-radius: 10px">
{{announcement_details.announcement_body}}
</p>
<li>Like: {{like}}</li>
<li>Love: {{love}}</li>
<li>Angry: {{angry}}</li>
<img src=http://images.gmanews.tv/webpics/2021/11/rastaman_2021_11_07_16_56_21.png>
<img src=https://cdn.w600.comps.canstockphoto.com/announcement-red-vintage-isolated-seal-drawings_csp24798234.jpg>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import announcements, details
from .views import AnnouncementView, details, addAnnouncement
urlpatterns = [
path('', announcements, name='announcements'),
path('announcements/<int:announcement_id>/details/', details, name='details')
#path('', announcements, name='announcements'),
path('', AnnouncementView.as_view(), name='announcement'),
path('<int:announcement_id>/details/', details, name='details'),
path('add/', addAnnouncement, name='addAnnouncement')
]
app_name = "announcements"
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from . import models
from .models import Announcement, Reaction
from .forms import AddAnnouncementForm
from django.views import View
from django.views.generic.list import ListView
def index(request):
return HttpResponse('This is the Announcement Board!')
def announcements(request):
all_announcements = models.Announcement.objects.order_by("-id")
context = {
"all_announcements": all_announcements
}
return render(request, 'announcements/announcements.html', context)
class AnnouncementView(View):
def get(self, request):
all_announcements = models.Announcement.objects.order_by("-id")
context = {
"all_announcements": all_announcements
}
return render(request, 'announcements/announcements.html', context)
def details(request, announcement_id):
announcement_details = models.Announcement.objects.get(pk=announcement_id)
......@@ -33,3 +34,13 @@ def details(request, announcement_id):
"angry": angry,
}
return render(request, "announcements/details.html", context)
def addAnnouncement(request):
if request.method == 'POST':
add_announcement = AddAnnouncementForm(request.POST)
if add_announcement.is_valid():
new_announcement = add_announcement.save()
return redirect('announcements:addAnnouncement')
else:
add_announcement = AddAnnouncementForm()
return render(request, 'announcements/addAnnouncements.html', {'add_announcement': add_announcement})
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