2017-04-13 09:48:50 +00:00
|
|
|
import datetime, os
|
|
|
|
|
2017-03-31 17:33:19 +00:00
|
|
|
from django.views.generic import ListView, TemplateView, DetailView, View
|
2017-03-07 23:00:17 +00:00
|
|
|
from django.views.generic.edit import CreateView, UpdateView
|
2017-01-22 11:59:57 +00:00
|
|
|
from django.conf import settings
|
2017-02-19 12:15:55 +00:00
|
|
|
from django.views.decorators.http import require_safe
|
2017-03-12 14:43:41 +00:00
|
|
|
from django.http import Http404, HttpResponse
|
2017-02-19 12:15:55 +00:00
|
|
|
from django.utils.decorators import method_decorator
|
2017-03-07 23:00:17 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.shortcuts import redirect
|
|
|
|
from django.urls import reverse
|
2017-04-13 09:48:50 +00:00
|
|
|
|
|
|
|
import icalendar
|
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
from camps.mixins import CampViewMixin
|
2017-03-18 15:22:16 +00:00
|
|
|
from .mixins import CreateProposalMixin, EnsureUnapprovedProposalMixin, EnsureUserOwnsProposalMixin, EnsureWritableCampMixin, PictureViewMixin, EnsureCFSOpenMixin
|
2017-03-12 14:43:41 +00:00
|
|
|
from . import models
|
2017-03-31 17:25:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
############## ical calendar ########################################################
|
|
|
|
|
|
|
|
|
2017-03-31 17:42:10 +00:00
|
|
|
class ICSView(CampViewMixin, View):
|
2017-03-31 17:25:48 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
2017-04-13 12:01:50 +00:00
|
|
|
eventinstances = models.EventInstance.objects.filter(event__camp=self.camp)
|
2017-04-13 09:48:50 +00:00
|
|
|
type_ = request.GET.get('type', None)
|
|
|
|
location = request.GET.get('location', None)
|
|
|
|
|
|
|
|
if type_:
|
|
|
|
try:
|
|
|
|
eventtype = models.EventType.objects.get(
|
|
|
|
slug=type_
|
|
|
|
)
|
|
|
|
eventinstances = eventinstances.filter(event__event_type=eventtype)
|
|
|
|
except models.EventType.DoesNotExist:
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
if location:
|
|
|
|
try:
|
|
|
|
eventlocation = models.EventLocation.objects.get(
|
|
|
|
slug=location,
|
|
|
|
camp=self.camp,
|
|
|
|
)
|
|
|
|
eventinstances = eventinstances.filter(location__slug=location)
|
|
|
|
except models.EventLocation.DoesNotExist:
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
cal = icalendar.Calendar()
|
|
|
|
for event_instance in eventinstances:
|
|
|
|
cal.add_component(event_instance.get_ics_event())
|
|
|
|
|
2017-04-13 12:14:44 +00:00
|
|
|
response = HttpResponse(cal.to_ical())
|
|
|
|
response['Content-Type'] = 'text/calendar'
|
|
|
|
response['Content-Disposition'] = 'inline; filename={}.ics'.format(self.camp.slug)
|
|
|
|
return response
|
2017-03-07 23:00:17 +00:00
|
|
|
|
|
|
|
|
2017-03-12 18:06:03 +00:00
|
|
|
############## proposals ########################################################
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
|
2017-03-12 18:06:03 +00:00
|
|
|
class ProposalListView(LoginRequiredMixin, CampViewMixin, ListView):
|
|
|
|
model = models.SpeakerProposal
|
|
|
|
template_name = 'proposal_list.html'
|
|
|
|
context_object_name = 'speakerproposal_list'
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
def get_queryset(self, **kwargs):
|
2017-03-12 18:06:03 +00:00
|
|
|
# only show speaker proposals for the current user
|
2017-03-12 14:43:41 +00:00
|
|
|
return super().get_queryset().filter(user=self.request.user)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2017-03-14 17:06:23 +00:00
|
|
|
# also add eventproposals to the context
|
2017-03-12 18:06:03 +00:00
|
|
|
context['eventproposal_list'] = models.EventProposal.objects.filter(camp=self.camp, user=self.request.user)
|
2017-03-12 14:43:41 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2017-03-18 15:22:16 +00:00
|
|
|
class SpeakerProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, CreateView):
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.SpeakerProposal
|
2017-03-07 23:00:17 +00:00
|
|
|
fields = ['name', 'biography', 'picture_small', 'picture_large']
|
2017-03-12 18:06:03 +00:00
|
|
|
template_name = 'speakerproposal_form.html'
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-03-14 17:06:23 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})
|
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-03-18 15:22:16 +00:00
|
|
|
class SpeakerProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView):
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.SpeakerProposal
|
2017-03-12 14:43:41 +00:00
|
|
|
fields = ['name', 'biography', 'picture_small', 'picture_large']
|
2017-03-12 18:06:03 +00:00
|
|
|
template_name = 'speakerproposal_form.html'
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-03-12 18:06:03 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-03-12 19:54:33 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
if form.instance.proposal_status == models.UserSubmittedModel.PROPOSAL_PENDING:
|
2017-04-01 19:45:43 +00:00
|
|
|
messages.warning(self.request, "Your speaker proposal has been reverted to status draft. Please submit it again when you are ready.")
|
2017-03-12 19:54:33 +00:00
|
|
|
form.instance.proposal_status = models.UserSubmittedModel.PROPOSAL_DRAFT
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
|
2017-03-18 15:22:16 +00:00
|
|
|
class SpeakerProposalSubmitView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView):
|
2017-03-12 19:54:33 +00:00
|
|
|
model = models.SpeakerProposal
|
|
|
|
fields = []
|
|
|
|
template_name = 'speakerproposal_submit.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.proposal_status = models.UserSubmittedModel.PROPOSAL_PENDING
|
|
|
|
messages.info(self.request, "Your proposal has been submitted and is now pending approval")
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
2017-03-12 18:06:03 +00:00
|
|
|
|
|
|
|
class SpeakerProposalDetailView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, DetailView):
|
|
|
|
model = models.SpeakerProposal
|
|
|
|
template_name = 'speakerproposal_detail.html'
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(require_safe, name='dispatch')
|
2017-03-17 18:40:47 +00:00
|
|
|
class SpeakerProposalPictureView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, PictureViewMixin, DetailView):
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.SpeakerProposal
|
2017-03-07 23:00:17 +00:00
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2017-03-14 17:06:23 +00:00
|
|
|
# is the proposal owned by current user?
|
|
|
|
if self.get_object().user != request.user:
|
2017-03-12 14:43:41 +00:00
|
|
|
raise Http404()
|
|
|
|
|
2017-03-17 18:40:47 +00:00
|
|
|
# get and return the response
|
2017-03-29 22:20:14 +00:00
|
|
|
response = self.get_picture_response('/public/speakerproposals/%(campslug)s/%(proposaluuid)s/%(filename)s' % {
|
|
|
|
'campslug': self.camp.slug,
|
|
|
|
'proposaluuid': self.get_object().uuid,
|
|
|
|
'filename': os.path.basename(self.picture.name),
|
|
|
|
})
|
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
return response
|
2017-03-07 23:00:17 +00:00
|
|
|
|
|
|
|
|
2017-03-18 15:22:16 +00:00
|
|
|
class EventProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, CreateView):
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.EventProposal
|
2017-03-12 14:43:41 +00:00
|
|
|
fields = ['title', 'abstract', 'event_type', 'speakers']
|
2017-03-12 18:06:03 +00:00
|
|
|
template_name = 'eventproposal_form.html'
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2017-03-12 18:06:03 +00:00
|
|
|
context['form'].fields['speakers'].queryset = models.SpeakerProposal.objects.filter(camp=self.camp, user=self.request.user)
|
2017-03-12 15:16:24 +00:00
|
|
|
context['form'].fields['event_type'].queryset = models.EventType.objects.filter(public=True)
|
2017-03-12 14:43:41 +00:00
|
|
|
return context
|
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2017-03-18 15:22:16 +00:00
|
|
|
class EventProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView):
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.EventProposal
|
2017-03-12 14:52:24 +00:00
|
|
|
fields = ['title', 'abstract', 'event_type', 'speakers']
|
2017-03-12 18:06:03 +00:00
|
|
|
template_name = 'eventproposal_form.html'
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2017-03-12 18:06:03 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})
|
2017-03-12 15:16:24 +00:00
|
|
|
|
2017-03-12 19:54:33 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
if form.instance.proposal_status == models.UserSubmittedModel.PROPOSAL_PENDING:
|
2017-04-01 19:45:43 +00:00
|
|
|
messages.warning(self.request, "Your event proposal has been reverted to status draft. Please submit it again when you are ready.")
|
2017-03-12 19:54:33 +00:00
|
|
|
form.instance.proposal_status = models.UserSubmittedModel.PROPOSAL_DRAFT
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
|
2017-03-18 15:22:16 +00:00
|
|
|
class EventProposalSubmitView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView):
|
2017-03-12 19:54:33 +00:00
|
|
|
model = models.EventProposal
|
|
|
|
fields = []
|
|
|
|
template_name = 'eventproposal_submit.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.proposal_status = models.UserSubmittedModel.PROPOSAL_PENDING
|
|
|
|
messages.info(self.request, "Your proposal has been submitted and is now pending approval")
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2017-03-12 18:06:03 +00:00
|
|
|
class EventProposalDetailView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, DetailView):
|
|
|
|
model = models.EventProposal
|
|
|
|
template_name = 'eventproposal_detail.html'
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
################## speakers ###############################################
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2017-02-19 13:04:31 +00:00
|
|
|
|
2017-02-19 12:15:55 +00:00
|
|
|
@method_decorator(require_safe, name='dispatch')
|
2017-03-17 18:40:47 +00:00
|
|
|
class SpeakerPictureView(CampViewMixin, PictureViewMixin, DetailView):
|
2017-02-19 12:15:55 +00:00
|
|
|
model = models.Speaker
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2017-03-29 22:20:14 +00:00
|
|
|
# get and return the response
|
|
|
|
response = self.get_picture_response(path='/public/speakers/%(campslug)s/%(slug)s/%(filename)s' % {
|
|
|
|
'campslug': self.camp.slug,
|
|
|
|
'slug': self.get_object().slug,
|
|
|
|
'filename': os.path.basename(self.picture.name),
|
|
|
|
})
|
2017-02-19 12:15:55 +00:00
|
|
|
return response
|
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-03-09 23:45:50 +00:00
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
################## events ##############################################
|
2017-01-23 17:57:30 +00:00
|
|
|
|
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-03-12 14:43:41 +00:00
|
|
|
class EventDetailView(CampViewMixin, DetailView):
|
|
|
|
model = models.Event
|
|
|
|
template_name = 'schedule_event_detail.html'
|
|
|
|
|
|
|
|
|
|
|
|
################## schedule #############################################
|
|
|
|
|
|
|
|
|
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-04-13 11:42:14 +00:00
|
|
|
context = super(ScheduleView, self).get_context_data(**kwargs)
|
2017-04-14 21:29:30 +00:00
|
|
|
eventinstances = models.EventInstance.objects.filter(event__in=self.camp.events.all()).select_related()
|
2017-04-13 11:42:14 +00:00
|
|
|
type_slug = self.request.GET.get('type', None)
|
|
|
|
location_slug = self.request.GET.get('location', None)
|
|
|
|
|
|
|
|
if type_slug:
|
2017-01-23 17:57:30 +00:00
|
|
|
try:
|
|
|
|
eventtype = models.EventType.objects.get(
|
2017-04-13 11:42:14 +00:00
|
|
|
slug=type_slug
|
2017-01-23 17:57:30 +00:00
|
|
|
)
|
|
|
|
except models.EventType.DoesNotExist:
|
|
|
|
raise Http404
|
|
|
|
|
2017-04-13 11:42:14 +00:00
|
|
|
context['eventtype'] = eventtype
|
|
|
|
context['get_string'] = '?type={}'.format(type_slug)
|
|
|
|
eventinstances = eventinstances.filter(event__event_type=eventtype)
|
|
|
|
|
|
|
|
if location_slug:
|
2017-02-08 22:34:24 +00:00
|
|
|
try:
|
|
|
|
eventlocation = models.EventLocation.objects.get(
|
2017-04-13 11:42:14 +00:00
|
|
|
slug=location_slug,
|
2017-02-08 22:34:24 +00:00
|
|
|
camp=self.camp,
|
|
|
|
)
|
|
|
|
except models.EventLocation.DoesNotExist:
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
context['location'] = eventlocation
|
2017-04-13 11:42:14 +00:00
|
|
|
get_part = 'location={}'.format(location_slug)
|
|
|
|
if 'get_string' in context:
|
|
|
|
context['get_string'] = context['get_string'] + '&{}'.format(get_part)
|
|
|
|
else:
|
|
|
|
context['get_string'] = '?{}'.format(get_part)
|
|
|
|
|
2017-02-08 22:34:24 +00:00
|
|
|
eventinstances = eventinstances.filter(location=eventlocation)
|
2017-04-13 11:42:14 +00:00
|
|
|
|
2017-02-08 22:34:24 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|