modified models, urls, and views to prepare for html pages

parent 15477754
......@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_gitgud.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -20,8 +20,8 @@ class Location(models.Model):
class Event(models.Model):
target_datetime= models.DateTimeField()
activity = models.TextField(max_length=1000, default='')
target_datetime= models.DateTimeField()
estimated_hours = models.FloatField()
location = models.ForeignKey(
Location,
......@@ -38,5 +38,7 @@ class Event(models.Model):
return '{}'.format(self.activity)
def get_absolute_url(self):
return reverse('event_detail', args=[str(self.activity)])
return reverse('widgetcalendar:event-detail', kwargs={'pk': self.pk})
def get_edit_url(self):
return reverse('widgetcalendar:event-edit', kwargs={'pk' : self.pk} )
\ No newline at end of file
from django.urls import path
from .views import index
from .views import index, EventDetailView, EditEventView, AddEventView
urlpatterns = [
path('', index, name='index'),
path('', index, name='Calendar'),
path('events/<int:pk>/details/', EventDetailView.as_view(), name ="event-detail"),
path('events/add/', AddEventView.as_view(), name ="event-add"),
]
app_name = "widgetcalendar"
\ No newline at end of file
from django.http import HttpResponse
from .models import Event
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.shortcuts import render
#Date format source: https://ourcodeworld.com/articles/read/555/how-to-format-datetime-objects-in-the-view-and-template-in-django
# def index(request):
# return_string = ''
# for events in Event.objects.all():
# return_string += 'Date and Time: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {} {}-{}<br>Mode: {}<br>Venue: {}<br></br>'.format(
# events.target_datetime.strftime("%x, %I:%M %p"), events.activity, events.estimated_hours, events.course.code, events.course.title, events.course.section, events.location.mode, events.location.venue
# )
# html_string = '<html><head>Widget\'s Calendar of Activities<br></br></head><body>{}</body><html>'.format(return_string)
# return HttpResponse(html_string)
def index(request):
return_string = ''
for events in Event.objects.all():
return_string += 'Date and Time: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {} {}-{}<br>Mode: {}<br>Venue: {}<br></br>'.format(
events.target_datetime.strftime("%x, %I:%M %p"), events.activity, events.estimated_hours, events.course.code, events.course.title, events.course.section, events.location.mode, events.location.venue
)
html_string = '<html><head>Widget\'s Calendar of Activities<br></br></head><body>{}</body><html>'.format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
events = Event.objects.all()
context = {'events': events}
return render(request, 'widgetcalendar/calendar.html', context)
class EventDetailView(DetailView):
model = Event
template_name = 'widgetcalendar/event-details.html'
class EditEventView(UpdateView):
model = Event
fields = '__all__'
template_name = 'widgetcalendar/event-edit.html'
class AddEventView(CreateView):
model = Event
fields = '__all__'
template_name = 'widgetcalendar/event-add.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