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 @@
db.sqlite3
.DS_Store
**/**/__pycache__/**
**/**/**/__pycache__/__init__.cpython-39.pyc
**/**/**/__pycache__/**
from django.urls import path
from .views import index
from .views import (
announcements, AnnouncementCreateView, AnnouncementDetailView, AnnouncementUpdateView
)
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'
from django.http import HttpResponse
from .models import Announcement, Reaction
from dashboard.models import WidgetUser
from .models import Announcement
from django.shortcuts import render
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(
announcement.title,
announcement.author.first_name,
announcement.author.last_name,
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
)
announcement_body = '{}<br>'.format(announcement.body)
announcement_reactions = ''
class AnnouncementCreateView(CreateView):
model = Announcement
template_name = "announcement_board/announcement-add.html"
fields = ['title','body','author']
announcement_reactions += 'Like: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Like').tally)
announcement_reactions += 'Love: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Love').tally)
announcement_reactions += 'Angry: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Angry').tally)
return_string += announcement_heading + announcement_body + announcement_reactions +'<br>'
html_string ='<html>{}</html>'.format(return_string)
return HttpResponse('Widget’s Announcement Board<br><br>Announcements:<br>'+html_string)
class AnnouncementUpdateView(UpdateView):
model = Announcement
template_name = "announcement_board/announcement-edit.html"
fields = ['title','body','author']
\ 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