Commit 86d2ff98 authored by Alec Dayupay's avatar Alec Dayupay

Edited announcements

parent 1b22d175
from django.forms import ModelForm
from .models import Announcement
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = '__all__'
\ No newline at end of file
from django.db import models
from django.urls import reverse
class Announcement(models.Model):
title = models.CharField(max_length = 50)
......@@ -9,6 +10,9 @@ class Announcement(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("announcement-details", kwargs={'pk': self.pk})
class Reaction(models.Model):
Like = 'Like'
Love = 'Love'
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Annoucement{% endblock %}
{% block content %}
<p>Add a new announcement:</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save New Announcement">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block heading %}{{ object.title }}{% endblock %}
{% block content %}
<p>by {{ object.author }}</p>
<p>{{ object.datetime }}</p>
<p>{{ object.body }}</p>
<p><br>Reactions:</p>
{% for reac in object.reaction_set.all %}
<p>by {{ reac.name }}: {{ reac.tally }}</p>
{% endfor %}
<input type="button" value="Edit Post" onclick="location.href='{% url 'forumpost-edit' object.pk %}'"/>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Announcement{% endblock %}
{% block content %}
<p>Edit Announcement:</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save Changes to Announcement">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block heading %}Welcome to Widget's Forum!{% endblock %}
{% block content %}
<p>Announcements:</p>
{% for ann in announcements %}
<p><a href="{% url 'announcement-details' ann.pk %}">{{ ann.title }} by {{ ann.author }}</a></p>
{% endfor %}
<input type="button" value="New Post" onclick="location.href='{% url 'announcement-add' %}'"/>
{% endblock %}
{% block links %}
<p><a href="http://localhost:8000/dashboard/">Dashboard</a></p>
<p><a href="http://localhost:8000/announcements/">Announcement</a></p>
<p><a href="http://localhost:8000/assignments/">Assignment</a></p>
<p><a href="http://localhost:8000/calendar/">Calendar</a></p>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from . import views
from .views import (AnnouncementDetailView, AnnouncementCreateView, AnnouncementUpdateView)
urlpatterns = [
path('', index, name='index'),
path('', views.announcements, name="announcements"),
path('announcements/<int:pk>/details/', AnnouncementDetailView.as_view(), name="announcement-details"),
path('announcements/add/', AnnouncementCreateView.as_view(), name="announcement-add"),
path('announcements/<int:pk>/edit/', AnnouncementUpdateView.as_view(), name="announcement-edit"),
]
\ No newline at end of file
app_name = "announcements"
from django.http import HttpResponse
from .models import Announcement, Reaction
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Announcement
def index(request):
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
def announcements(request):
return render(request, 'announcements/announcements.html', {'announcements': Announcement.objects.order_by('-pub_datetime')})
response = "Widget's Announcement Board<br><br>Announcements:<br>"
for announcement in announcements:
response += "{} by {} published {}:<br>{}<br>".format(
announcement.title,
announcement.author,
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
announcement.body
)
class AnnouncementDetailView(DetailView):
model = Announcement
template_name = 'announcements/announcement-details.html'
for reaction in reactions:
if reaction.announcement == announcement:
response += "{}: {}<br>".format(
reaction.name,
str(reaction.tally)
)
response += "<br>"
return HttpResponse(response)
class AnnouncementCreateView(CreateView):
model = Announcement
fields = '__all__'
template_name = 'announcements/announcement-add.html'
class AnnouncementUpdateView(UpdateView):
model = Announcement
fields = '__all__'
template_name = 'announcements/announcement-edit.html'
\ 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