2017-07-11 20:02:19 +00:00
|
|
|
import logging
|
2018-05-20 16:16:20 +00:00
|
|
|
from collections import OrderedDict
|
2017-04-13 09:48:50 +00:00
|
|
|
|
2017-03-31 17:33:19 +00:00
|
|
|
from django.views.generic import ListView, TemplateView, DetailView, View
|
2018-08-19 16:21:04 +00:00
|
|
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
2017-01-22 11:59:57 +00:00
|
|
|
from django.conf import settings
|
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-08-22 09:48:51 +00:00
|
|
|
from django.contrib.admin.views.decorators import staff_member_required
|
2017-03-07 23:00:17 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.contrib import messages
|
2018-05-20 16:16:20 +00:00
|
|
|
from django.urls import reverse, reverse_lazy
|
2017-08-22 11:00:42 +00:00
|
|
|
from django.template import Engine, Context
|
2018-05-20 16:16:20 +00:00
|
|
|
from django.shortcuts import redirect
|
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from betterforms.multiform import MultiModelForm
|
2017-04-13 09:48:50 +00:00
|
|
|
import icalendar
|
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
from camps.mixins import CampViewMixin
|
2018-08-19 16:21:04 +00:00
|
|
|
from program.models import Url, UrlType
|
2017-07-11 20:02:19 +00:00
|
|
|
from .mixins import (
|
|
|
|
EnsureUserOwnsProposalMixin,
|
|
|
|
EnsureWritableCampMixin,
|
2018-05-23 21:28:27 +00:00
|
|
|
EnsureCFPOpenMixin,
|
|
|
|
UrlViewMixin,
|
2017-07-11 20:02:19 +00:00
|
|
|
)
|
|
|
|
from .email import (
|
2018-05-26 08:24:52 +00:00
|
|
|
add_new_eventproposal_email,
|
|
|
|
add_new_speakerproposal_email,
|
2017-07-11 20:02:19 +00:00
|
|
|
add_speakerproposal_updated_email,
|
|
|
|
add_eventproposal_updated_email
|
|
|
|
)
|
2017-03-12 14:43:41 +00:00
|
|
|
from . import models
|
2018-06-03 17:41:49 +00:00
|
|
|
from .forms import SpeakerProposalForm, EventProposalForm
|
2018-05-20 16:16:20 +00:00
|
|
|
|
|
|
|
|
2017-07-11 20:02:19 +00:00
|
|
|
logger = logging.getLogger("bornhack.%s" % __name__)
|
2017-03-31 17:25:48 +00:00
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
2018-03-04 14:48:57 +00:00
|
|
|
# ical calendar
|
2017-03-31 17:25:48 +00:00
|
|
|
|
|
|
|
|
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):
|
2018-05-26 18:14:48 +00:00
|
|
|
eventinstances = models.EventInstance.objects.filter(
|
|
|
|
event__track__camp=self.camp
|
|
|
|
)
|
2017-08-13 22:50:54 +00:00
|
|
|
|
|
|
|
# Type query
|
|
|
|
type_query = request.GET.get('type', None)
|
|
|
|
if type_query:
|
|
|
|
type_slugs = type_query.split(',')
|
|
|
|
types = models.EventType.objects.filter(
|
|
|
|
slug__in=type_slugs
|
|
|
|
)
|
|
|
|
eventinstances = eventinstances.filter(event__event_type__in=types)
|
|
|
|
|
|
|
|
# Location query
|
|
|
|
location_query = request.GET.get('location', None)
|
|
|
|
if location_query:
|
|
|
|
location_slugs = location_query.split(',')
|
|
|
|
locations = models.EventLocation.objects.filter(
|
|
|
|
slug__in=location_slugs,
|
|
|
|
camp=self.camp,
|
|
|
|
)
|
|
|
|
eventinstances = eventinstances.filter(location__in=locations)
|
|
|
|
|
|
|
|
# Video recording query
|
|
|
|
video_query = request.GET.get('video', None)
|
|
|
|
if video_query:
|
|
|
|
video_states = video_query.split(',')
|
|
|
|
query_kwargs = {}
|
|
|
|
|
|
|
|
if 'has-recording' in video_states:
|
|
|
|
query_kwargs['event__video_url__isnull'] = False
|
|
|
|
|
|
|
|
if 'to-be-recorded' in video_states:
|
|
|
|
query_kwargs['event__video_recording'] = True
|
|
|
|
|
|
|
|
if 'not-to-be-recorded' in video_states:
|
|
|
|
if 'event__video_recording' in query_kwargs:
|
|
|
|
del query_kwargs['event__video_recording']
|
|
|
|
else:
|
|
|
|
query_kwargs['event__video_recording'] = False
|
|
|
|
|
|
|
|
eventinstances = eventinstances.filter(**query_kwargs)
|
2017-04-13 09:48:50 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
|
|
|
# proposals list view
|
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
|
2018-05-20 16:16:20 +00:00
|
|
|
context['eventproposal_list'] = models.EventProposal.objects.filter(track__camp=self.camp, user=self.request.user)
|
|
|
|
context['eventtype_list'] = models.EventType.objects.filter(public=True)
|
2017-03-12 14:43:41 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
|
|
|
# speakerproposal views
|
|
|
|
|
|
|
|
|
|
|
|
class SpeakerProposalCreateView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, CreateView):
|
|
|
|
""" This view allows a user to create a new SpeakerProposal linked to an existing EventProposal """
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.SpeakerProposal
|
|
|
|
template_name = 'speakerproposal_form.html'
|
2018-06-03 17:41:49 +00:00
|
|
|
form_class = SpeakerProposalForm
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
""" Get the eventproposal object """
|
|
|
|
self.eventproposal = get_object_or_404(models.EventProposal, pk=kwargs['event_uuid'])
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
2017-03-14 17:06:23 +00:00
|
|
|
def get_success_url(self):
|
2018-05-20 16:16:20 +00:00
|
|
|
return reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug})
|
|
|
|
|
2018-06-03 17:41:49 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
"""
|
|
|
|
Set camp and eventtype for the form
|
|
|
|
"""
|
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
kwargs.update({
|
|
|
|
'camp': self.camp,
|
|
|
|
'eventtype': self.eventproposal.event_type
|
|
|
|
})
|
|
|
|
return kwargs
|
2017-03-14 17:06:23 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['eventproposal'] = self.eventproposal
|
|
|
|
return context
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
# set user before saving
|
|
|
|
form.instance.user = self.request.user
|
|
|
|
form.instance.camp = self.camp
|
2018-08-18 12:11:30 +00:00
|
|
|
|
|
|
|
if not form.instance.email:
|
|
|
|
form.instance.email = self.request.user.email
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
speakerproposal = form.save()
|
|
|
|
|
|
|
|
# add speakerproposal to eventproposal
|
|
|
|
self.eventproposal.speakers.add(speakerproposal)
|
|
|
|
|
2018-05-26 08:24:52 +00:00
|
|
|
# send mail to content team
|
|
|
|
if not add_new_speakerproposal_email(speakerproposal):
|
|
|
|
logger.error("Unable to send email to content team after new speakerproposal")
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
return redirect(
|
|
|
|
reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug})
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class SpeakerProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureUserOwnsProposalMixin, EnsureCFPOpenMixin, UpdateView):
|
|
|
|
"""
|
|
|
|
This view allows a user to update an existing SpeakerProposal.
|
|
|
|
"""
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.SpeakerProposal
|
|
|
|
template_name = 'speakerproposal_form.html'
|
2018-06-03 17:41:49 +00:00
|
|
|
form_class = SpeakerProposalForm
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2018-06-03 17:41:49 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
"""
|
|
|
|
Set camp and eventtype for the form
|
|
|
|
"""
|
|
|
|
kwargs = super().get_form_kwargs()
|
2018-05-20 16:16:20 +00:00
|
|
|
if self.get_object().eventproposals.count() == 1:
|
|
|
|
# determine which form to use based on the type of event associated with the proposal
|
2018-06-03 17:41:49 +00:00
|
|
|
eventtype = self.get_object().eventproposals.get().event_type
|
2018-05-20 16:16:20 +00:00
|
|
|
else:
|
|
|
|
# more than one eventproposal. If all events are the same type we can still show a non-generic form here
|
|
|
|
eventtypes = set()
|
|
|
|
for ep in self.get_object().eventproposals.all():
|
|
|
|
eventtypes.add(ep.event_type)
|
|
|
|
if len(eventtypes) == 1:
|
2018-06-03 17:41:49 +00:00
|
|
|
eventtype = self.get_object().eventproposals.get().event_type
|
|
|
|
else:
|
|
|
|
# more than one type of event for this person, return the generic speakerproposal form
|
|
|
|
eventtype = None
|
|
|
|
|
|
|
|
# add camp and eventtype to form kwargs
|
|
|
|
kwargs.update({
|
|
|
|
'camp': self.camp,
|
|
|
|
'eventtype': eventtype
|
|
|
|
})
|
|
|
|
|
|
|
|
return kwargs
|
2018-05-20 16:16:20 +00:00
|
|
|
|
2018-05-26 08:24:52 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
"""
|
|
|
|
Change the speakerproposal status to pending
|
|
|
|
"""
|
|
|
|
# set proposal status to pending
|
|
|
|
form.instance.proposal_status = models.SpeakerProposal.PROPOSAL_PENDING
|
|
|
|
speakerproposal = form.save()
|
|
|
|
|
|
|
|
# send mail to content team
|
|
|
|
if not add_speakerproposal_updated_email(speakerproposal):
|
|
|
|
logger.error("Unable to send email to content team after speakerproposal update")
|
|
|
|
|
|
|
|
# message user and redirect
|
|
|
|
messages.info(self.request, "Your proposal is now pending approval by the content team.")
|
|
|
|
return redirect(reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug}))
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
|
|
|
|
class SpeakerProposalDeleteView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureUserOwnsProposalMixin, EnsureCFPOpenMixin, DeleteView):
|
|
|
|
"""
|
|
|
|
This view allows a user to delete an existing SpeakerProposal object, as long as it is not linked to any EventProposals
|
|
|
|
"""
|
|
|
|
model = models.SpeakerProposal
|
|
|
|
template_name = 'proposal_delete.html'
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
# do not permit deleting if this speakerproposal is linked to any eventproposals
|
|
|
|
if self.get_object().eventproposals.exists():
|
|
|
|
messages.error(request, "Cannot delete a person while it is associated with one or more eventproposals. Delete those first.")
|
|
|
|
return redirect(reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug}))
|
|
|
|
|
|
|
|
# continue with the request
|
|
|
|
return super().get(request, *args, **kwargs)
|
2017-07-11 20:02:19 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
messages.success(self.request, "Proposal '%s' has been deleted." % self.object.name)
|
|
|
|
return reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug})
|
2017-07-11 20:02:19 +00:00
|
|
|
|
2017-03-12 19:54:33 +00:00
|
|
|
|
2018-05-20 18:29:56 +00:00
|
|
|
|
2018-05-26 12:53:39 +00:00
|
|
|
class SpeakerProposalDetailView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, DetailView):
|
2018-05-20 18:29:56 +00:00
|
|
|
model = models.SpeakerProposal
|
|
|
|
template_name = 'speakerproposal_detail.html'
|
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
|
|
|
# eventproposal views
|
2017-03-12 19:54:33 +00:00
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class EventProposalTypeSelectView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, ListView):
|
|
|
|
"""
|
|
|
|
This view is for selecting the type of event to submit (when adding a new eventproposal to an existing speakerproposal)
|
|
|
|
"""
|
|
|
|
model = models.EventType
|
|
|
|
template_name = 'event_type_select.html'
|
2017-03-12 19:54:33 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
""" Get the speakerproposal object """
|
|
|
|
self.speaker = get_object_or_404(models.SpeakerProposal, pk=kwargs['speaker_uuid'])
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
2017-03-12 19:54:33 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_queryset(self, **kwargs):
|
|
|
|
""" We only allow submissions of events with EventTypes where public=True """
|
|
|
|
return super().get_queryset().filter(public=True)
|
2017-03-12 18:06:03 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
""" Make speakerproposal object available in template """
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['speaker'] = self.speaker
|
|
|
|
return context
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class EventProposalSelectPersonView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, ListView):
|
|
|
|
"""
|
|
|
|
This view is for selecting an existing speakerproposal to add to an existing eventproposal
|
|
|
|
"""
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.SpeakerProposal
|
2018-05-20 16:16:20 +00:00
|
|
|
template_name = 'event_proposal_select_person.html'
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
""" Get EventProposal from url kwargs """
|
|
|
|
self.eventproposal = get_object_or_404(models.EventProposal, pk=kwargs['event_uuid'], user=request.user)
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_queryset(self, **kwargs):
|
|
|
|
""" Filter out any speakerproposals already added to this eventproposal """
|
|
|
|
return self.eventproposal.get_available_speakerproposals().all()
|
2017-03-29 22:20:14 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
""" Make eventproposal object available in template """
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['eventproposal'] = self.eventproposal
|
|
|
|
return context
|
2017-03-07 23:00:17 +00:00
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class EventProposalAddPersonView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, UpdateView):
|
|
|
|
"""
|
|
|
|
This view is for adding an existing speakerproposal to an existing eventproposal
|
|
|
|
"""
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.EventProposal
|
2018-05-20 16:16:20 +00:00
|
|
|
template_name = 'event_proposal_add_person.html'
|
|
|
|
fields = []
|
|
|
|
pk_url_kwarg = 'event_uuid'
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
""" Get the speakerproposal object """
|
|
|
|
self.speakerproposal = get_object_or_404(models.SpeakerProposal, pk=kwargs['speaker_uuid'], user=request.user)
|
2018-05-20 19:11:53 +00:00
|
|
|
return super().dispatch(request, *args, **kwargs)
|
2018-05-20 16:16:20 +00:00
|
|
|
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
""" Make speakerproposal object available in template """
|
2017-03-12 14:43:41 +00:00
|
|
|
context = super().get_context_data(**kwargs)
|
2018-05-20 16:16:20 +00:00
|
|
|
context['speakerproposal'] = self.speakerproposal
|
2017-03-12 14:43:41 +00:00
|
|
|
return context
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.speakers.add(self.speakerproposal)
|
2018-05-27 15:19:19 +00:00
|
|
|
messages.success(self.request, "%s has been added as %s for %s" % (
|
|
|
|
self.speakerproposal.name,
|
|
|
|
form.instance.event_type.host_title,
|
|
|
|
form.instance.title
|
|
|
|
))
|
2018-05-20 16:16:20 +00:00
|
|
|
return redirect(self.get_success_url())
|
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2018-05-24 09:43:46 +00:00
|
|
|
class EventProposalRemovePersonView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, UpdateView):
|
|
|
|
"""
|
|
|
|
This view is for removing a speakerproposal from an existing eventproposal
|
|
|
|
"""
|
|
|
|
model = models.EventProposal
|
|
|
|
template_name = 'event_proposal_remove_person.html'
|
|
|
|
fields = []
|
|
|
|
pk_url_kwarg = 'event_uuid'
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
""" Get the speakerproposal object and check a few things """
|
|
|
|
# get the speakerproposal object from URL kwargs
|
|
|
|
self.speakerproposal = get_object_or_404(models.SpeakerProposal, pk=kwargs['speaker_uuid'], user=request.user)
|
2018-05-27 15:19:19 +00:00
|
|
|
return super().dispatch(request, *args, **kwargs)
|
2018-05-24 09:43:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
""" Make speakerproposal object available in template """
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['speakerproposal'] = self.speakerproposal
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
""" Remove the speaker from the event """
|
|
|
|
if self.speakerproposal not in self.get_object().speakers.all():
|
|
|
|
# this speaker is not associated with this event
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
if self.get_object().speakers.count() == 1:
|
|
|
|
messages.error(self.request, "Cannot delete the last person associalted with event!")
|
2018-05-27 15:19:19 +00:00
|
|
|
return redirect(self.get_success_url())
|
2018-05-24 09:43:46 +00:00
|
|
|
|
2018-05-27 15:19:19 +00:00
|
|
|
# remove speakerproposal from eventproposal
|
2018-05-24 09:43:46 +00:00
|
|
|
form.instance.speakers.remove(self.speakerproposal)
|
2018-05-27 15:19:19 +00:00
|
|
|
messages.success(self.request, "%s has been removed from %s" % (
|
2018-05-24 09:43:46 +00:00
|
|
|
self.speakerproposal.name,
|
|
|
|
self.get_object().title
|
|
|
|
))
|
2018-05-27 15:19:19 +00:00
|
|
|
return redirect(self.get_success_url())
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2018-05-24 09:43:46 +00:00
|
|
|
return reverse(
|
|
|
|
'program:eventproposal_detail', kwargs={
|
|
|
|
'camp_slug': self.camp.slug,
|
|
|
|
'pk': self.get_object().uuid
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class EventProposalCreateView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, CreateView):
|
|
|
|
"""
|
|
|
|
This view allows a user to create a new eventproposal linked to an existing speakerproposal
|
|
|
|
"""
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.EventProposal
|
|
|
|
template_name = 'eventproposal_form.html'
|
2018-06-03 17:41:49 +00:00
|
|
|
form_class = EventProposalForm
|
2017-03-12 15:16:24 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
""" Get the speakerproposal object """
|
|
|
|
self.speakerproposal = get_object_or_404(models.SpeakerProposal, pk=self.kwargs['speaker_uuid'])
|
|
|
|
self.event_type = get_object_or_404(models.EventType, slug=self.kwargs['event_type_slug'])
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
""" Make speakerproposal object available in template """
|
2017-07-31 20:05:44 +00:00
|
|
|
context = super().get_context_data(**kwargs)
|
2018-05-20 16:16:20 +00:00
|
|
|
context['speaker'] = self.speakerproposal
|
|
|
|
context['event_type'] = self.event_type
|
2017-07-31 20:05:44 +00:00
|
|
|
return context
|
|
|
|
|
2018-06-03 17:41:49 +00:00
|
|
|
def get_form_kwargs(self):
|
2018-05-20 16:16:20 +00:00
|
|
|
"""
|
2018-06-03 17:41:49 +00:00
|
|
|
Set camp and eventtype for the form
|
2018-05-20 16:16:20 +00:00
|
|
|
"""
|
2018-06-03 17:41:49 +00:00
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
kwargs.update({
|
|
|
|
'camp': self.camp,
|
|
|
|
'eventtype': self.event_type
|
|
|
|
})
|
|
|
|
return kwargs
|
2018-05-20 16:16:20 +00:00
|
|
|
|
2017-03-12 19:54:33 +00:00
|
|
|
def form_valid(self, form):
|
2018-05-20 16:16:20 +00:00
|
|
|
# set camp and user for this eventproposal
|
2018-08-19 16:21:04 +00:00
|
|
|
eventproposal = form.save(user=self.request.user, event_type=self.event_type)
|
2017-07-11 20:02:19 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
# add the speakerproposal to the eventproposal
|
|
|
|
eventproposal.speakers.add(self.speakerproposal)
|
2017-07-11 20:02:19 +00:00
|
|
|
|
2018-05-26 08:24:52 +00:00
|
|
|
# send mail to content team
|
|
|
|
if not add_new_eventproposal_email(eventproposal):
|
|
|
|
logger.error("Unable to send email to content team after new eventproposal")
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
# all good
|
|
|
|
return redirect(self.get_success_url())
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug})
|
2017-03-12 19:54:33 +00:00
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class EventProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureUserOwnsProposalMixin, EnsureCFPOpenMixin, UpdateView):
|
2017-03-12 19:54:33 +00:00
|
|
|
model = models.EventProposal
|
2018-05-20 16:16:20 +00:00
|
|
|
template_name = 'eventproposal_form.html'
|
2018-06-03 17:41:49 +00:00
|
|
|
form_class = EventProposalForm
|
2018-05-20 16:16:20 +00:00
|
|
|
|
2018-06-03 17:41:49 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
"""
|
|
|
|
Set camp and eventtype for the form
|
|
|
|
"""
|
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
kwargs.update({
|
|
|
|
'camp': self.camp,
|
|
|
|
'eventtype': self.get_object().event_type
|
|
|
|
})
|
|
|
|
return kwargs
|
2017-03-12 19:54:33 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
""" Make speakerproposal and eventtype objects available in the template """
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['event_type'] = self.get_object().event_type
|
|
|
|
return context
|
2017-03-12 19:54:33 +00:00
|
|
|
|
2018-05-26 08:24:52 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
# set status to pending and save eventproposal
|
|
|
|
form.instance.proposal_status = models.EventProposal.PROPOSAL_PENDING
|
|
|
|
eventproposal = form.save()
|
|
|
|
|
|
|
|
# send email to content team
|
|
|
|
if not add_eventproposal_updated_email(eventproposal):
|
|
|
|
logger.error("Unable to send email to content team after eventproposal update")
|
|
|
|
|
|
|
|
# message for the user and redirect
|
|
|
|
messages.info(self.request, "Your proposal is now pending approval by the content team.")
|
|
|
|
return redirect(reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug}))
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
|
|
|
|
class EventProposalDeleteView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureUserOwnsProposalMixin, EnsureCFPOpenMixin, DeleteView):
|
2017-03-12 18:06:03 +00:00
|
|
|
model = models.EventProposal
|
2018-05-20 16:16:20 +00:00
|
|
|
template_name = 'proposal_delete.html'
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
messages.success(self.request, "Proposal '%s' has been deleted." % self.object.title)
|
|
|
|
return reverse('program:proposal_list', kwargs={'camp_slug': self.camp.slug})
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
|
2018-05-26 12:53:39 +00:00
|
|
|
class EventProposalDetailView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, DetailView):
|
2018-05-20 18:29:56 +00:00
|
|
|
model = models.EventProposal
|
|
|
|
template_name = 'eventproposal_detail.html'
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
|
|
|
# combined proposal views
|
2017-02-19 13:04:31 +00:00
|
|
|
|
2017-02-19 12:15:55 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class CombinedProposalTypeSelectView(LoginRequiredMixin, CampViewMixin, ListView):
|
|
|
|
"""
|
|
|
|
A view which allows the user to select event type without anything else on the page
|
|
|
|
"""
|
|
|
|
model = models.EventType
|
|
|
|
template_name = 'event_type_select.html'
|
|
|
|
|
|
|
|
def get_queryset(self, **kwargs):
|
|
|
|
""" We only allow submissions of events with EventTypes where public=True """
|
|
|
|
return super().get_queryset().filter(public=True)
|
|
|
|
|
|
|
|
|
2018-05-20 19:11:53 +00:00
|
|
|
class CombinedProposalPersonSelectView(LoginRequiredMixin, CampViewMixin, ListView):
|
|
|
|
"""
|
|
|
|
A view which allows the user to 1) choose between existing SpeakerProposals or
|
|
|
|
2) pressing a button to create a new SpeakerProposal.
|
|
|
|
Redirect straight to 2) if no existing SpeakerProposals exist.
|
|
|
|
"""
|
|
|
|
model = models.SpeakerProposal
|
|
|
|
template_name = 'combined_proposal_select_person.html'
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Check that we have a valid EventType
|
|
|
|
"""
|
|
|
|
# get EventType from url kwargs
|
|
|
|
self.eventtype = get_object_or_404(models.EventType, slug=self.kwargs['event_type_slug'])
|
|
|
|
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
2018-05-20 19:54:36 +00:00
|
|
|
def get_queryset(self, **kwargs):
|
|
|
|
# only show speaker proposals for the current user
|
|
|
|
return super().get_queryset().filter(user=self.request.user)
|
|
|
|
|
2018-05-20 19:11:53 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
"""
|
|
|
|
Add EventType to template context
|
|
|
|
"""
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['eventtype'] = self.eventtype
|
|
|
|
return context
|
|
|
|
|
2018-05-20 19:54:36 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
""" If we don't have any existing SpeakerProposals just redirect directly to the combined submit view """
|
|
|
|
if not self.get_queryset().exists():
|
|
|
|
return redirect(reverse_lazy('program:proposal_combined_submit', kwargs={'camp_slug': self.camp.slug, 'event_type_slug': self.eventtype.slug}))
|
|
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
|
2018-05-20 19:11:53 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class CombinedProposalSubmitView(LoginRequiredMixin, CampViewMixin, CreateView):
|
|
|
|
"""
|
|
|
|
This view is used by users to submit CFP proposals.
|
|
|
|
It allows the user to submit an EventProposal and a SpeakerProposal together.
|
2018-05-20 19:11:53 +00:00
|
|
|
It can also be used with a preselected SpeakerProposal uuid in url kwargs
|
2018-05-20 16:16:20 +00:00
|
|
|
"""
|
|
|
|
template_name = 'combined_proposal_submit.html'
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Check that we have a valid EventType
|
|
|
|
"""
|
2018-05-20 19:11:53 +00:00
|
|
|
# get EventType from url kwargs
|
|
|
|
self.eventtype = get_object_or_404(models.EventType, slug=self.kwargs['event_type_slug'])
|
2018-05-20 16:16:20 +00:00
|
|
|
|
2018-05-20 19:11:53 +00:00
|
|
|
return super().dispatch(request, *args, **kwargs)
|
2018-05-20 16:16:20 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
"""
|
|
|
|
Add EventType to template context
|
|
|
|
"""
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['eventtype'] = self.eventtype
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
"""
|
2018-05-20 19:11:53 +00:00
|
|
|
Save the object(s) here before redirecting
|
2018-05-20 16:16:20 +00:00
|
|
|
"""
|
2018-05-20 19:11:53 +00:00
|
|
|
if hasattr(self, 'speakerproposal'):
|
2018-08-19 16:21:04 +00:00
|
|
|
eventproposal = form.save(user=self.request.user, event_type=self.eventtype)
|
2018-05-20 19:11:53 +00:00
|
|
|
eventproposal.speakers.add(self.speakerproposal)
|
|
|
|
else:
|
|
|
|
# first save the SpeakerProposal
|
|
|
|
speakerproposal = form['speakerproposal'].save(commit=False)
|
|
|
|
speakerproposal.camp = self.camp
|
|
|
|
speakerproposal.user = self.request.user
|
2018-08-18 12:11:30 +00:00
|
|
|
if not speakerproposal.email:
|
|
|
|
speakerproposal.email = self.request.user.email
|
2018-05-20 19:11:53 +00:00
|
|
|
speakerproposal.save()
|
2018-05-20 16:16:20 +00:00
|
|
|
|
2018-05-20 19:11:53 +00:00
|
|
|
# then save the eventproposal
|
2018-08-19 16:21:04 +00:00
|
|
|
eventproposal = form['eventproposal'].save(user=self.request.user, event_type=self.eventtype)
|
2018-05-20 19:11:53 +00:00
|
|
|
eventproposal.user = self.request.user
|
|
|
|
eventproposal.event_type = self.eventtype
|
|
|
|
eventproposal.save()
|
|
|
|
|
|
|
|
# add the speakerproposal to the eventproposal
|
|
|
|
eventproposal.speakers.add(speakerproposal)
|
2018-05-20 16:16:20 +00:00
|
|
|
|
2018-05-26 08:24:52 +00:00
|
|
|
# send mail(s) to content team
|
|
|
|
if not add_new_eventproposal_email(eventproposal):
|
|
|
|
logger.error("Unable to send email to content team after new eventproposal")
|
|
|
|
if not hasattr(self, 'speakerproposal'):
|
|
|
|
if not add_new_speakerproposal_email(speakerproposal):
|
|
|
|
logger.error("Unable to send email to content team after new speakerproposal")
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
# all good
|
|
|
|
return redirect(reverse_lazy('program:proposal_list', kwargs={'camp_slug': self.camp.slug}))
|
|
|
|
|
|
|
|
def get_form_class(self):
|
|
|
|
"""
|
2018-05-20 19:11:53 +00:00
|
|
|
Unless we have an existing SpeakerProposal we must show two forms on the page.
|
2018-05-20 16:16:20 +00:00
|
|
|
We use betterforms.MultiModelForm to combine two forms on the page
|
|
|
|
"""
|
2018-05-20 19:11:53 +00:00
|
|
|
if hasattr(self, 'speakerproposal'):
|
|
|
|
# we already have a speakerproposal, just show an eventproposal form
|
2018-06-03 17:41:49 +00:00
|
|
|
return EventProposalForm
|
2018-05-20 16:16:20 +00:00
|
|
|
|
|
|
|
# build our MultiModelForm
|
|
|
|
class CombinedProposalSubmitForm(MultiModelForm):
|
|
|
|
form_classes = OrderedDict((
|
|
|
|
('speakerproposal', SpeakerProposalForm),
|
|
|
|
('eventproposal', EventProposalForm),
|
|
|
|
))
|
|
|
|
|
|
|
|
# return the form class
|
|
|
|
return CombinedProposalSubmitForm
|
|
|
|
|
2018-06-03 17:41:49 +00:00
|
|
|
def get_form_kwargs(self):
|
2018-05-20 16:16:20 +00:00
|
|
|
"""
|
2018-06-03 17:41:49 +00:00
|
|
|
Set camp and eventtype for the form
|
2018-05-20 16:16:20 +00:00
|
|
|
"""
|
2018-06-03 17:41:49 +00:00
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
kwargs.update({
|
|
|
|
'camp': self.camp,
|
|
|
|
'eventtype': self.eventtype
|
|
|
|
})
|
|
|
|
return kwargs
|
2018-05-20 16:16:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
###################################################################################################
|
|
|
|
# speaker views
|
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
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
|
|
|
# event views
|
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'
|
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
|
|
|
# schedule views
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
|
2017-07-23 09:31:22 +00:00
|
|
|
class NoScriptScheduleView(CampViewMixin, TemplateView):
|
|
|
|
template_name = "noscript_schedule_view.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-07-23 09:31:22 +00:00
|
|
|
context = super().get_context_data(**kwargs)
|
2018-05-26 18:14:48 +00:00
|
|
|
context['eventinstances'] = models.EventInstance.objects.filter(
|
|
|
|
event__track__camp=self.camp
|
|
|
|
).order_by('when')
|
2017-07-23 09:31:22 +00:00
|
|
|
return context
|
2017-01-22 11:59:57 +00:00
|
|
|
|
|
|
|
|
2017-07-23 09:31:22 +00:00
|
|
|
class ScheduleView(CampViewMixin, TemplateView):
|
|
|
|
template_name = 'schedule_overview.html'
|
2017-01-23 22:58:41 +00:00
|
|
|
|
2018-07-17 22:58:33 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
If no events are scheduled redirect to the event page
|
|
|
|
"""
|
|
|
|
response = super().dispatch(request, *args, **kwargs)
|
|
|
|
if not models.EventInstance.objects.filter(event__track__camp=self.camp).exists():
|
|
|
|
return(redirect(reverse('program:event_index', kwargs={'camp_slug': self.camp.slug})))
|
|
|
|
return response
|
|
|
|
|
2017-07-23 09:31:22 +00:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
context = super(ScheduleView, self).get_context_data(**kwargs)
|
2018-03-04 14:48:57 +00:00
|
|
|
context['schedule_midnight_offset_hours'] = settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS
|
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
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class CallForParticipationView(CampViewMixin, TemplateView):
|
2018-05-25 12:27:53 +00:00
|
|
|
template_name = 'call_for_participation.html'
|
|
|
|
|
2017-08-22 09:48:51 +00:00
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
###################################################################################################
|
|
|
|
# control center csv
|
2017-08-22 09:48:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ProgramControlCenter(CampViewMixin, TemplateView):
|
|
|
|
template_name = "control/index.html"
|
|
|
|
|
|
|
|
@method_decorator(staff_member_required)
|
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
|
return super().dispatch(*args, **kwargs)
|
|
|
|
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
proposals = models.EventProposal.objects.filter(
|
|
|
|
camp=self.camp
|
|
|
|
).select_related('user', 'event')
|
|
|
|
context['proposals'] = proposals
|
|
|
|
|
2017-08-22 11:00:42 +00:00
|
|
|
engine = Engine.get_default()
|
|
|
|
template = engine.get_template('control/proposal_overview.csv')
|
|
|
|
csv = template.render(Context(context))
|
|
|
|
context['csv'] = csv
|
|
|
|
|
|
|
|
return context
|
2018-05-20 16:16:20 +00:00
|
|
|
|
2018-05-23 21:28:27 +00:00
|
|
|
###################################################################################################
|
|
|
|
# URL views
|
|
|
|
|
|
|
|
class UrlCreateView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, UrlViewMixin, CreateView):
|
|
|
|
model = models.Url
|
|
|
|
template_name = 'url_form.html'
|
|
|
|
fields = ['urltype', 'url']
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
"""
|
|
|
|
Set the proposal FK before saving
|
2018-07-17 20:43:16 +00:00
|
|
|
Set proposal as pending if it isn't already
|
2018-05-23 21:28:27 +00:00
|
|
|
"""
|
|
|
|
if hasattr(self, 'eventproposal') and self.eventproposal:
|
2018-06-26 21:37:20 +00:00
|
|
|
# this URL belongs to an eventproposal
|
2018-05-23 21:28:27 +00:00
|
|
|
form.instance.eventproposal = self.eventproposal
|
|
|
|
url = form.save()
|
2018-06-26 21:37:20 +00:00
|
|
|
if self.eventproposal.proposal_status != models.SpeakerProposal.PROPOSAL_PENDING:
|
|
|
|
self.eventproposal.proposal_status = models.SpeakerProposal.PROPOSAL_PENDING
|
|
|
|
self.eventproposal.save()
|
2018-07-17 20:43:16 +00:00
|
|
|
messages.success(self.request, "%s is now pending review by the Content Team." % self.eventproposal.title)
|
2018-05-23 21:28:27 +00:00
|
|
|
else:
|
2018-06-26 21:37:20 +00:00
|
|
|
# this URL belongs to a speakerproposal
|
2018-05-23 21:28:27 +00:00
|
|
|
form.instance.speakerproposal = self.speakerproposal
|
|
|
|
url = form.save()
|
2018-06-26 21:37:20 +00:00
|
|
|
if self.speakerproposal.proposal_status != models.SpeakerProposal.PROPOSAL_PENDING:
|
|
|
|
self.speakerproposal.proposal_status = models.SpeakerProposal.PROPOSAL_PENDING
|
|
|
|
self.speakerproposal.save()
|
2018-07-17 20:43:16 +00:00
|
|
|
messages.success(self.request, "%s is now pending review by the Content Team." % self.speakerproposal.name)
|
2018-05-23 21:28:27 +00:00
|
|
|
|
|
|
|
messages.success(self.request, "URL saved.")
|
|
|
|
|
|
|
|
# all good
|
2018-07-17 20:43:16 +00:00
|
|
|
return redirect(reverse_lazy('program:proposal_list', kwargs={'camp_slug': self.camp.slug}))
|
2018-05-23 21:28:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UrlUpdateView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, UrlViewMixin, UpdateView):
|
|
|
|
model = models.Url
|
|
|
|
template_name = 'url_form.html'
|
|
|
|
fields = ['urltype', 'url']
|
|
|
|
pk_url_kwarg = 'url_uuid'
|
|
|
|
|
2018-06-26 21:37:20 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
"""
|
2018-07-17 20:43:16 +00:00
|
|
|
Set proposal as pending if it isn't already
|
2018-06-26 21:37:20 +00:00
|
|
|
"""
|
|
|
|
if hasattr(self, 'eventproposal') and self.eventproposal:
|
|
|
|
# this URL belongs to a speakerproposal
|
|
|
|
url = form.save()
|
|
|
|
if self.eventproposal.proposal_status != models.SpeakerProposal.PROPOSAL_PENDING:
|
|
|
|
self.eventproposal.proposal_status = models.SpeakerProposal.PROPOSAL_PENDING
|
|
|
|
self.eventproposal.save()
|
|
|
|
messages.success(self.request, "%s is now pending review by the Content Team." % self.eventproposal.title)
|
|
|
|
else:
|
|
|
|
# this URL belongs to a speakerproposal
|
|
|
|
url = form.save()
|
|
|
|
if self.speakerproposal.proposal_status != models.SpeakerProposal.PROPOSAL_PENDING:
|
|
|
|
self.speakerproposal.proposal_status = models.SpeakerProposal.PROPOSAL_PENDING
|
|
|
|
self.speakerproposal.save()
|
|
|
|
messages.success(self.request, "%s is now pending review by the Content Team." % self.speakerproposal.name)
|
|
|
|
|
|
|
|
messages.success(self.request, "URL saved.")
|
|
|
|
|
|
|
|
# all good
|
2018-07-17 20:43:16 +00:00
|
|
|
return redirect(reverse_lazy('program:proposal_list', kwargs={'camp_slug': self.camp.slug}))
|
2018-06-26 21:37:20 +00:00
|
|
|
|
2018-05-23 21:28:27 +00:00
|
|
|
|
|
|
|
class UrlDeleteView(LoginRequiredMixin, CampViewMixin, EnsureWritableCampMixin, EnsureCFPOpenMixin, UrlViewMixin, DeleteView):
|
|
|
|
model = models.Url
|
|
|
|
template_name = 'url_delete.html'
|
|
|
|
pk_url_kwarg = 'url_uuid'
|
|
|
|
|
2018-07-17 20:43:16 +00:00
|
|
|
def delete(self, request, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Set proposal as pending if it isn't already
|
|
|
|
"""
|
|
|
|
if hasattr(self, 'eventproposal') and self.eventproposal:
|
|
|
|
# this URL belongs to a speakerproposal
|
|
|
|
if self.eventproposal.proposal_status != models.SpeakerProposal.PROPOSAL_PENDING:
|
|
|
|
self.eventproposal.proposal_status = models.SpeakerProposal.PROPOSAL_PENDING
|
|
|
|
self.eventproposal.save()
|
|
|
|
messages.success(self.request, "%s is now pending review by the Content Team." % self.eventproposal.title)
|
|
|
|
else:
|
|
|
|
# this URL belongs to a speakerproposal
|
|
|
|
if self.speakerproposal.proposal_status != models.SpeakerProposal.PROPOSAL_PENDING:
|
|
|
|
self.speakerproposal.proposal_status = models.SpeakerProposal.PROPOSAL_PENDING
|
|
|
|
self.speakerproposal.save()
|
|
|
|
messages.success(self.request, "%s is now pending review by the Content Team." % self.speakerproposal.name)
|
|
|
|
|
|
|
|
self.object = self.get_object()
|
|
|
|
self.object.delete()
|
|
|
|
messages.success(self.request, "URL deleted.")
|
|
|
|
|
|
|
|
# all good
|
|
|
|
return redirect(reverse_lazy('program:proposal_list', kwargs={'camp_slug': self.camp.slug}))
|
|
|
|
|