2016-07-13 20:37:20 +00:00
|
|
|
from collections import OrderedDict
|
2016-08-04 21:03:39 +00:00
|
|
|
import datetime
|
2016-08-07 13:49:30 +00:00
|
|
|
from django.views.generic import ListView, TemplateView, DetailView
|
2016-12-28 23:15:13 +00:00
|
|
|
from camps.mixins import CampViewMixin
|
2016-07-13 20:37:20 +00:00
|
|
|
from . import models
|
2017-01-22 11:59:57 +00:00
|
|
|
from django.http import Http404
|
|
|
|
import datetime
|
|
|
|
from django.conf import settings
|
2016-07-13 20:37:20 +00:00
|
|
|
|
2016-08-08 17:45:32 +00:00
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
class SpeakerDetailView(CampViewMixin, DetailView):
|
2016-08-08 17:45:32 +00:00
|
|
|
model = models.Speaker
|
|
|
|
template_name = 'speaker_detail.html'
|
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
|
|
|
|
class SpeakerListView(CampViewMixin, ListView):
|
2016-08-08 17:36:13 +00:00
|
|
|
model = models.Speaker
|
|
|
|
template_name = 'speaker_list.html'
|
|
|
|
|
2017-01-23 17:57:30 +00:00
|
|
|
def get_queryset(self, *args, **kwargs):
|
|
|
|
return models.Speaker.objects.filter(camp=self.camp)
|
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
|
|
|
|
class EventListView(CampViewMixin, ListView):
|
2016-08-08 17:36:13 +00:00
|
|
|
model = models.Event
|
|
|
|
template_name = 'event_list.html'
|
2016-07-13 20:37:20 +00:00
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
|
2017-02-17 16:17:21 +00:00
|
|
|
class ScheduleView(CampViewMixin, TemplateView):
|
|
|
|
def get_template_names(self):
|
|
|
|
if 'day' in self.kwargs:
|
|
|
|
return 'schedule_day.html'
|
|
|
|
return 'schedule_overview.html'
|
2016-07-13 20:37:20 +00:00
|
|
|
|
2017-02-08 22:34:24 +00:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
2017-01-23 17:57:30 +00:00
|
|
|
if 'type' in self.request.GET:
|
|
|
|
try:
|
|
|
|
eventtype = models.EventType.objects.get(
|
|
|
|
slug=self.request.GET['type']
|
|
|
|
)
|
|
|
|
except models.EventType.DoesNotExist:
|
|
|
|
raise Http404
|
|
|
|
|
2017-02-08 22:34:24 +00:00
|
|
|
if 'location' in self.request.GET:
|
|
|
|
try:
|
|
|
|
eventlocation = models.EventLocation.objects.get(
|
|
|
|
slug=self.request.GET['location'],
|
|
|
|
camp=self.camp,
|
|
|
|
)
|
|
|
|
except models.EventLocation.DoesNotExist:
|
|
|
|
raise Http404
|
|
|
|
|
2017-02-17 16:17:21 +00:00
|
|
|
context = super(ScheduleView, self).get_context_data(**kwargs)
|
2017-02-08 22:34:24 +00:00
|
|
|
eventinstances = models.EventInstance.objects.filter(event__in=self.camp.events.all())
|
|
|
|
|
2017-01-23 17:57:30 +00:00
|
|
|
if 'type' in self.request.GET:
|
2017-02-08 22:34:24 +00:00
|
|
|
context['eventtype'] = eventtype
|
|
|
|
eventinstances = eventinstances.filter(event__event_type=eventtype)
|
|
|
|
|
|
|
|
if 'location' in self.request.GET:
|
|
|
|
context['location'] = eventlocation
|
|
|
|
eventinstances = eventinstances.filter(location=eventlocation)
|
|
|
|
context['eventinstances'] = eventinstances
|
2017-01-23 17:57:30 +00:00
|
|
|
|
2017-02-17 16:17:21 +00:00
|
|
|
# Do stuff if we are dealing with a day schedule
|
|
|
|
if 'day' in kwargs:
|
|
|
|
when = datetime.datetime(year=int(self.kwargs['year']), month=int(self.kwargs['month']), day=int(self.kwargs['day']))
|
|
|
|
eventinstances = models.EventInstance.objects.filter(event__in=self.camp.events.all())
|
|
|
|
skip = []
|
|
|
|
for ei in eventinstances:
|
|
|
|
if ei.schedule_date != when.date():
|
|
|
|
skip.append(ei.id)
|
|
|
|
else:
|
|
|
|
if 'type' in self.request.GET:
|
|
|
|
eventtype = models.EventType.objects.get(
|
|
|
|
slug=self.request.GET['type']
|
|
|
|
)
|
|
|
|
if ei.event.event_type != eventtype:
|
|
|
|
skip.append(ei.id)
|
|
|
|
eventinstances = eventinstances.exclude(id__in=skip).order_by('event__event_type')
|
|
|
|
if 'location' in self.request.GET:
|
|
|
|
eventlocation = models.EventLocation.objects.get(
|
|
|
|
camp=self.camp,
|
|
|
|
slug=self.request.GET['location']
|
2017-01-22 11:59:57 +00:00
|
|
|
)
|
2017-02-17 16:17:21 +00:00
|
|
|
eventinstances = eventinstances.filter(location=eventlocation)
|
2017-01-22 11:59:57 +00:00
|
|
|
|
2017-02-17 16:17:21 +00:00
|
|
|
context['eventinstances'] = eventinstances
|
2017-01-22 11:59:57 +00:00
|
|
|
|
2017-02-17 16:17:21 +00:00
|
|
|
start = when + datetime.timedelta(hours=settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS)
|
|
|
|
timeslots = []
|
|
|
|
# calculate how many timeslots we have in the schedule based on the lenght of the timeslots in minutes,
|
|
|
|
# and the number of minutes in 24 hours
|
|
|
|
for i in range(0,int((24*60)/settings.SCHEDULE_TIMESLOT_LENGTH_MINUTES)):
|
|
|
|
timeslot = start + datetime.timedelta(minutes=i*settings.SCHEDULE_TIMESLOT_LENGTH_MINUTES)
|
|
|
|
timeslots.append(timeslot)
|
|
|
|
context['timeslots'] = timeslots
|
2017-01-23 22:58:41 +00:00
|
|
|
|
2017-02-17 16:17:21 +00:00
|
|
|
# include the components to make the urls
|
|
|
|
context['urlyear'] = self.kwargs['year']
|
|
|
|
context['urlmonth'] = self.kwargs['month']
|
|
|
|
context['urlday'] = self.kwargs['day']
|
2017-01-23 22:58:41 +00:00
|
|
|
|
2017-01-22 11:59:57 +00:00
|
|
|
return context
|
2016-08-04 21:03:39 +00:00
|
|
|
|
2016-08-07 13:49:30 +00:00
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
class EventDetailView(CampViewMixin, DetailView):
|
2016-08-07 13:49:30 +00:00
|
|
|
model = models.Event
|
2017-02-17 16:17:21 +00:00
|
|
|
template_name = 'schedule_event_detail.html'
|
2016-08-07 13:49:30 +00:00
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
|
2017-01-22 11:59:57 +00:00
|
|
|
class CallForSpeakersView(CampViewMixin, TemplateView):
|
|
|
|
def get_template_names(self):
|
2017-01-28 18:30:52 +00:00
|
|
|
return '%s_call_for_speakers.html' % self.camp.slug
|
2017-01-22 11:59:57 +00:00
|
|
|
|