Commit 8b41b926 authored by Michael Lopez's avatar Michael Lopez

added announcement edit and create view on views.py

parent 8a8d3f8f
from django.urls import path
from .views import AnnouncementDetailView
from .views import pageview
from .views import *
urlpatterns = [
path('', pageview, name='pageview'),
path('<int:pk>/details/', AnnouncementDetailView.as_view(), name="announcement_details"),
path("add/", )
]
app_name = "announcements"
\ No newline at end of file
import pytz # need to do "pip install pytz" for this to be activated
from .forms import *
from .models import Announcement, Reaction
from django.utils import timezone
from django.views.generic import ListView, DetailView
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from django.db.models import Sum
from django.shortcuts import render
from django.urls import reverse
def pageview(request):
model_object = Announcement.objects.order_by("-pub_datetime")
return render(request, "announcements/announcements.html", context={"announcement_list":model_object})
def UTC_to_PHTZ(utctime):
ph_tz = "%m/%d/%Y, %I:%M %p"
utc = utctime.replace(tzinfo=pytz.UTC)
local_tz = utc.astimezone(timezone.get_current_timezone)
return local_tz.strftime(ph_tz)
class AnnouncementListView(ListView):
model = Announcement
template_name = "announcements/announcements.html"
......@@ -35,4 +37,25 @@ class AnnouncementDetailView(DetailView):
context['pubpost_datetime'] = UTC_to_PHTZ(announcement.pub_datetime)
return context
class AnnouncementCreateView(CreateView):
model = Announcement
form_class = AddAnnouncement
template_name = "announcements/announcement-add.html"
def form_valid(self, form):
response = super().form_valid(form)
form.save()
return response
def get_success_url(self):
return reverse("announcement_board:announcement_details", args=(self.object.pk,))
class AnnouncementEditView(UpdateView):
model = Announcement
form_class = AddAnnouncement
template_name = "announcements/announcement-edit.html"
def form_valid(self, form):
response = super().form_valid(form)
form.save()
return response
def get_success_url(self):
return reverse("announcement_board:announcement_details", args=(self.object.pk,))
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