Commit da2041a0 authored by Nics De Vega's avatar Nics De Vega

modified views and urls for announcement_board

parent 9b3c8a73
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
db.sqlite3 db.sqlite3
.DS_Store .DS_Store
**/**/__pycache__/** **/**/__pycache__/**
**/**/**/__pycache__/__init__.cpython-39.pyc **/**/**/__pycache__/**
from django.urls import path from django.urls import path
from .views import index from .views import (
announcements, AnnouncementCreateView, AnnouncementDetailView, AnnouncementUpdateView
)
urlpatterns = [ urlpatterns = [
path('',index,name='index') path('',announcements, name='announcements'),
path('<int:pk>/details/',AnnouncementDetailView.as_view(),name='announcement-details'),
path('add/',AnnouncementCreateView.as_view(),name='announcement-add'),
path('<int:pk>/edit/',AnnouncementUpdateView.as_view(),name='announcement-edit'),
] ]
app_name = 'announcement_board' app_name = 'announcement_board'
from django.http import HttpResponse from .models import Announcement
from .models import Announcement, Reaction from django.shortcuts import render
from dashboard.models import WidgetUser from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
def announcements(request):
return render (request, 'announcement_board/announcements.html',
{'announcements':Announcement.objects.order_by('-pub_datetime')})
def index(request): class AnnouncementDetailView(DetailView):
model = Announcement
template_name = "announcement_board/announcement-details.html"
return_string = '<body>'
for announcement in Announcement.objects.all():
announcement_heading = '{} by {} {} published {}:<br>'.format( class AnnouncementCreateView(CreateView):
announcement.title, model = Announcement
announcement.author.first_name, template_name = "announcement_board/announcement-add.html"
announcement.author.last_name, fields = ['title','body','author']
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
)
announcement_body = '{}<br>'.format(announcement.body)
announcement_reactions = ''
announcement_reactions += 'Like: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Like').tally) class AnnouncementUpdateView(UpdateView):
announcement_reactions += 'Love: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Love').tally) model = Announcement
announcement_reactions += 'Angry: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Angry').tally) template_name = "announcement_board/announcement-edit.html"
fields = ['title','body','author']
return_string += announcement_heading + announcement_body + announcement_reactions +'<br>' \ No newline at end of file
html_string ='<html>{}</html>'.format(return_string)
return HttpResponse('Widget’s Announcement Board<br><br>Announcements:<br>'+html_string)
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