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

parent 15477754
...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_gitgud.urls' ...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_gitgud.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
...@@ -20,8 +20,8 @@ class Location(models.Model): ...@@ -20,8 +20,8 @@ class Location(models.Model):
class Event(models.Model): class Event(models.Model):
target_datetime= models.DateTimeField()
activity = models.TextField(max_length=1000, default='') activity = models.TextField(max_length=1000, default='')
target_datetime= models.DateTimeField()
estimated_hours = models.FloatField() estimated_hours = models.FloatField()
location = models.ForeignKey( location = models.ForeignKey(
Location, Location,
...@@ -38,5 +38,7 @@ class Event(models.Model): ...@@ -38,5 +38,7 @@ class Event(models.Model):
return '{}'.format(self.activity) return '{}'.format(self.activity)
def get_absolute_url(self): 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 django.urls import path
from .views import index from .views import index, EventDetailView, EditEventView, AddEventView
urlpatterns = [ 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" app_name = "widgetcalendar"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Event 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 #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): def index(request):
return_string = '' events = Event.objects.all()
for events in Event.objects.all(): context = {'events': events}
return_string += 'Date and Time: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {} {}-{}<br>Mode: {}<br>Venue: {}<br></br>'.format( return render(request, 'widgetcalendar/calendar.html', context)
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
) class EventDetailView(DetailView):
html_string = '<html><head>Widget\'s Calendar of Activities<br></br></head><body>{}</body><html>'.format(return_string) model = Event
return HttpResponse(html_string) template_name = 'widgetcalendar/event-details.html'
\ No newline at end of file
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