Commit 32bda5ca authored by Jose Gabriel L. Salas's avatar Jose Gabriel L. Salas

updated paths in urls.py and created edit, update, and create classes in views.py

parent d1349b22
from django.urls import path from django.urls import path
from .views import index from .views import (calendar, EventDetailView, EventCreateView, EventUpdateView)
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('calendar/', calendar, name='calendar'),
path('calendar/events/<int:pk>/details/', EventDetailView, name='event-details'),
path('calendar/events/add/', EventCreateView, name='event-add'),
path('calendar/events/<int:pk>/edit/', EventUpdateView, name='event-edit'),
] ]
# This might be needed, depending on your Django version # This might be needed, depending on your Django version
app_name = "widget_calendar" app_name = "widget_calendar"
\ No newline at end of file
from django.http import HttpResponse from django.shortcuts import render, redirect
from django.views import View
from .models import Event from .models import Event
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
def index(request):
return_string = "<p>Widget's Calendar of Activities</p>" def index(request):
activities = Event.objects.all()
return render(request, 'calendar/calendar.html', {'activities':activities})
for events in Event.objects.all(): class EventDetailView(DetailView):
round_hours = ("{:0.0f}".format(events.estimated_hours)) model = Event
return_string += 'Date and Time: {}<br>'.format( template_name = "calendar/event-details.html"
events.target_datetime.strftime('%m/%d/%Y, %H:%M %p')
)
return_string += 'Activity: {}<br>'.format(events.activity)
return_string += 'Estimated Hours: {}<br>'.format(round_hours)
return_string += 'Course/Section: {} {}-{}<br>'.format(
events.course.code,
events.course.title,
events.course.section,
)
return_string += 'Mode: {}<br>'.format(events.location.mode)
return_string += 'Venue: {}<br>'.format(events.location.venue)
return_string += '<br>'
html_string = '<html><body>{}</body></html>'.format(return_string) class EventCreateView(CreateView):
model = Event
fields = '__all__'
template_name = "calendar/event-add.html"
return HttpResponse(html_string) class EventUpdateView(UpdateView):
model = Event
fields = '__all__'
template_name = 'calendar/event-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