bornhack-website/program/views.py

83 lines
2.4 KiB
Python
Raw Normal View History

2016-07-13 20:37:20 +00:00
from collections import OrderedDict
import datetime
2016-08-07 13:49:30 +00:00
from django.views.generic import ListView, TemplateView, DetailView
2016-07-13 20:37:20 +00:00
from camps.models import Day
from . import models
2016-08-08 17:45:32 +00:00
class SpeakerDetailView(DetailView):
model = models.Speaker
template_name = 'speaker_detail.html'
2016-08-08 17:36:13 +00:00
class SpeakerListView(ListView):
model = models.Speaker
template_name = 'speaker_list.html'
class EventListView(ListView):
model = models.Event
template_name = 'event_list.html'
2016-07-13 20:37:20 +00:00
class ProgramOverviewView(ListView):
2016-07-13 20:37:20 +00:00
model = models.Event
template_name = 'program_overview.html'
2016-07-13 20:37:20 +00:00
def get_context_data(self, **kwargs):
context = super(
ProgramOverviewView, self
2016-07-13 20:37:20 +00:00
).get_context_data(**kwargs)
days = Day.objects.all()
context['days'] = days
filter = {}
if 'type' in self.request.GET:
event_type = self.request.GET['type']
filter["event_type__slug"] = event_type
context['day_events'] = OrderedDict([
(
day,
self.get_queryset().filter(
days__in=[day],
**filter
).order_by(
'start'
)
)
2016-07-13 20:37:20 +00:00
for day in days
])
context['event_types'] = models.EventType.objects.all()
return context
class ProgramDayView(TemplateView):
template_name = 'program_day.html'
def get_context_data(self, **kwargs):
context = super(ProgramDayView, self).get_context_data(**kwargs)
year = int(kwargs['year'])
month = int(kwargs['month'])
day = int(kwargs['day'])
date = datetime.date(year=year, month=month, day=day)
day = Day.objects.filter(date=date)
2016-08-08 19:16:43 +00:00
context['date'] = date
2016-08-07 12:36:43 +00:00
context['events'] = models.Event.objects.filter(days=day).order_by('start', 'event_type')
context['event_types'] = models.EventType.objects.all()
context['days'] = Day.objects.filter(date__year=year)
2016-07-13 20:37:20 +00:00
return context
2016-07-13 17:13:47 +00:00
2016-08-07 13:49:30 +00:00
class EventDetailView(DetailView):
model = models.Event
template_name = 'program_event_detail.html'
def get_context_data(self, **kwargs):
context = super(EventDetailView, self).get_context_data(**kwargs)
# TODO: date__year is hardcoded here - need fix for 2017 :P
context['days'] = Day.objects.filter(date__year=2016)
return context