Commit cd649422 authored by Maso Crisostomo's avatar Maso Crisostomo

Fixed announcements app

parent 02fe00c4
from django.forms import ModelForm
from.models import Announcement
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = ["announcement_title", "announcement_body", "author"]
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block content %}
<form method="POST" action="add">
{% csrf_token %}
{{ announcement_form.as_p }}
<button class="button" type="submit">Save Announcement</button>
</form>
<br>
<a href="/announcements">Back to announcement board</a>
{% endblock %}
<!-- -->
\ No newline at end of file
......@@ -7,10 +7,9 @@
<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>Announcement Board</title> -->
<title>Announcements</title>
</head>
<body>
<!-- <script src="index.js"></script> -->
{% block content %}
{% endblock %}
......
......@@ -14,5 +14,5 @@
<p>No reactions are available.</p>
{% endif %}
{% load static %}
<img src="{% static image_url %}" alt="Photo of Post"/>
<img src="{% static image_url %}" alt="Photo of announcement"/>
{% endblock %}
\ No newline at end of file
......@@ -10,8 +10,10 @@
</ul>
{% else %}
<p>No announcements are available.</p>
{% endif %}
{% endif %}
<button type="button" onclick="location.href='add'">New Announcement</button>
{% endblock %}
<!-- -->
\ No newline at end of file
......@@ -4,12 +4,10 @@ from . import views
app_name = "announcements"
urlpatterns = [
# announcements/
path('', views.index, name='index'),
#announcements/1/details
# announcements/1/details
path("<int:announcement_id>/details", views.details, name="details"),
#announcements/1/reactions
# path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
#announcements/1/react
# path("<int:announcement_id>/react", views.react, name="react")
# announcements/add
path("add", views.add, name="add"),
]
\ No newline at end of file
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.shortcuts import render, redirect
import datetime
from .models import Announcement, Reaction
from .forms import AnnouncementForm
# Create your views here.
def index(request):
......@@ -23,32 +25,18 @@ def details(request, announcement_id):
raise Http404("Announcement does not exist!")
return render(request, "announcements/details.html", context)
# def reactions(request, announcement_id):
# response = "This are the reactions to announcement # %s."
# return HttpResponse(response % announcement_id)
# def react(request, announcement_id):
# return HttpResponse("You are reacting to announcement # %s." % announcement_id)
# this belongs in index
# announcements_list = Announcement.objects.order_by("pub_date")
# output = ", ".join([a.announcement_title for a in announcements_list])
# return HttpResponse(output)
# content = 'ANNOUNCEMENTS:<br/>'
# announcements = Announcement.objects.all()
# reacts = Reaction.objects.all()
# for i in announcements:
# announcement_date = i.pub_date.date().strftime("%m/%d/%Y")
# 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:
# if j.announcement == i:
# content += f'{j.reaction_name}: {j.tally}<br/>'
# content += '<br/>'
# return HttpResponse(content)
\ No newline at end of file
def add(request):
if request.method == "POST":
announcement_form = AnnouncementForm(request.POST)
if announcement_form.is_valid():
new_announcement = announcement_form.save()
return redirect("announcements:add")
else:
announcement_form = AnnouncementForm()
pub_date = datetime.datetime.now()
context = {
"announcement_form": announcement_form,
"pub_date": pub_date
}
return render(request, "announcements/add.html", context)
\ 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