Commit 3b893033 authored by Ross Batacan's avatar Ross Batacan

Updated announcements URL with created template announcements.html. New...

Updated announcements URL with created template announcements.html. New features include: Add Announcement Button, link to other appplications, list of announcements with hyperlinks
parent 79b393ca
<!--def announcements(request):-->
<!-- announcement = Announcement.objects.all()-->
<!-- response = "<h3>Widget's Announcement Board</h3>"-->
<!-- for every in announcement:-->
<!-- datetime = every.announcement_pub_datetime.strftime("%a, %b %d, %Y %I:%M %p")-->
<!-- response += "<p>{}".format(every.announcement_title) +\-->
<!-- " By {}".format(every.announcement_author.first_name) +\-->
<!-- " {}".format(every.announcement_author.last_name) +\-->
<!-- " published {}".format(datetime) +\-->
<!-- "<br>{}".format(every.announcement_body)-->
<!-- like_on_post = 0-->
<!-- love_on_post = 0-->
<!-- angry_on_post = 0-->
<!-- reactions = Reaction.objects.filter(reaction_announcement=every)-->
<!-- for every in reactions:-->
<!-- if every.reaction_name == "Like":-->
<!-- like_on_post = every.reaction_tally-->
<!-- elif every.reaction_name == "Love":-->
<!-- love_on_post = every.reaction_tally-->
<!-- elif every.reaction_name == "Angry":-->
<!-- angry_on_post = every.reaction_tally-->
<!-- response += "<br>like: {}".format(like_on_post) +\-->
<!-- "<br>love: {}".format(love_on_post) +\-->
<!-- "<br>angry: {}<br>".format(angry_on_post)-->
<!-- return HttpResponse(response)-->
{% extends 'base.html' %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block title %} Widget's Announcement Board {% endblock %}
{% block content %}
<h1>Welcome to Widget's Announcement Board!</h1>
<h3>Announcements:</h3>
{% for announcement in announcements %}
<a href="{{ announcement.get_absolute_url }}"> {{ announcement.announcement_title }}
by {{ announcement.announcement_author.first_name }} {{ announcement.announcement_author.last_name }}
</a> <br>
{% endfor %} <br>
<a href="{% url 'announcements:announcement-add' %}">
<button>New Announcement</button>
</a> <br><br>
<a href="">Dashboard</a> <br>
<a href="">Forum</a>
{% endblock %}
from django.urls import path
from . import views
from .views import Announcements, AnnouncementsDetailsView, AnnouncementsCreateView, AnnouncementsEditView
urlpatterns = [
path('', views.announcements, name="announcements"),
path('')
path('', Announcements, name="announcements"),
path('<int:pk>/details/', AnnouncementsDetailsView.as_view(), name="announcement-details"),
path('add/', AnnouncementsCreateView.as_view(), name="announcement-add"),
path('<int:pk>/edit/', AnnouncementsEditView.as_view(), name="announcement-edit"),
]
app_name = 'announcements'
\ No newline at end of file
......@@ -8,8 +8,13 @@ from .models import Announcement, Reaction
# Create your views here.
def home(request):
return render(request, 'announcements/announcements.html')
def Announcements(request):
announcements = Announcement.objects.order_by("announcement_pub_datetime")
context = {
"announcements": announcements,
}
return render(request, 'announcements/announcements.html', context)
class AnnouncementsDetailsView(DetailView):
model = Announcement
......@@ -24,39 +29,4 @@ class AnnouncementsEditView(UpdateView):
template_name = 'announcements/announcement-edit.html'
# def announcements(request):
# announcement = Announcement.objects.all()
#
# response = "<h3>Widget's Announcement Board</h3>"
#
# for every in announcement:
# datetime = every.announcement_pub_datetime.strftime("%a, %b %d, %Y %I:%M %p")
#
# response += "<p>{}".format(every.announcement_title) +\
# " By {}".format(every.announcement_author.first_name) +\
# " {}".format(every.announcement_author.last_name) +\
# " published {}".format(datetime) +\
# "<br>{}".format(every.announcement_body)
#
# like_on_post = 0
# love_on_post = 0
# angry_on_post = 0
# reactions = Reaction.objects.filter(reaction_announcement=every)
#
# for every in reactions:
# if every.reaction_name == "Like":
# like_on_post = every.reaction_tally
# elif every.reaction_name == "Love":
# love_on_post = every.reaction_tally
# elif every.reaction_name == "Angry":
# angry_on_post = every.reaction_tally
#
# response += "<br>like: {}".format(like_on_post) +\
# "<br>love: {}".format(love_on_post) +\
# "<br>angry: {}<br>".format(angry_on_post)
#
# return HttpResponse(response)
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