2020-02-12 12:10:41 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
from django.http import Http404
|
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
2017-03-12 14:43:41 +00:00
|
|
|
from django.urls import reverse
|
2020-02-12 12:10:41 +00:00
|
|
|
from django.views.generic.detail import SingleObjectMixin
|
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
from . import models
|
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class EnsureCFPOpenMixin(object):
|
2017-03-18 15:22:16 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
2018-05-20 16:16:20 +00:00
|
|
|
# do not permit this action if call for participation is not open
|
|
|
|
if not self.camp.call_for_participation_open:
|
|
|
|
messages.error(request, "The Call for Participation is not open.")
|
2018-03-04 14:48:57 +00:00
|
|
|
return redirect(
|
2019-06-16 12:32:24 +00:00
|
|
|
reverse("program:proposal_list", kwargs={"camp_slug": self.camp.slug})
|
2018-03-04 14:48:57 +00:00
|
|
|
)
|
2017-03-18 15:22:16 +00:00
|
|
|
|
|
|
|
# alright, continue with the request
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2017-03-12 19:54:33 +00:00
|
|
|
class EnsureUnapprovedProposalMixin(SingleObjectMixin):
|
2017-03-12 14:43:41 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
2017-03-12 18:06:03 +00:00
|
|
|
# do not permit editing if the proposal is already approved
|
2019-06-16 12:32:24 +00:00
|
|
|
if (
|
|
|
|
self.get_object().proposal_status
|
|
|
|
== models.UserSubmittedModel.PROPOSAL_APPROVED
|
|
|
|
):
|
|
|
|
messages.error(
|
|
|
|
request,
|
|
|
|
"This proposal has already been approved. Please contact the organisers if you need to modify something.",
|
|
|
|
)
|
|
|
|
return redirect(
|
|
|
|
reverse("program:proposal_list", kwargs={"camp_slug": self.camp.slug})
|
|
|
|
)
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
# alright, continue with the request
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2018-05-20 16:16:20 +00:00
|
|
|
class EnsureWritableCampMixin(object):
|
2017-03-12 14:43:41 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
2017-03-12 18:06:03 +00:00
|
|
|
# do not permit view if camp is in readonly mode
|
|
|
|
if self.camp.read_only:
|
|
|
|
messages.error(request, "No thanks")
|
2019-06-16 12:32:24 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("program:proposal_list", kwargs={"camp_slug": self.camp.slug})
|
|
|
|
)
|
2017-03-12 18:06:03 +00:00
|
|
|
|
|
|
|
# alright, continue with the request
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class EnsureUserOwnsProposalMixin(SingleObjectMixin):
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
# make sure that this proposal belongs to the logged in user
|
2017-03-12 14:43:41 +00:00
|
|
|
if self.get_object().user.username != request.user.username:
|
|
|
|
messages.error(request, "No thanks")
|
2018-03-04 14:48:57 +00:00
|
|
|
return redirect(
|
2019-06-16 12:32:24 +00:00
|
|
|
reverse("program:proposal_list", kwargs={"camp_slug": self.camp.slug})
|
2018-03-04 14:48:57 +00:00
|
|
|
)
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
# alright, continue with the request
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
2018-05-23 21:28:27 +00:00
|
|
|
|
|
|
|
class UrlViewMixin(object):
|
|
|
|
"""
|
|
|
|
Mixin with code shared between all the Url views
|
|
|
|
"""
|
2019-06-16 12:32:24 +00:00
|
|
|
|
2018-05-23 21:28:27 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Check that we have a valid SpeakerProposal or EventProposal and that it belongs to the current user
|
|
|
|
"""
|
|
|
|
# get the proposal
|
2019-06-16 12:32:24 +00:00
|
|
|
if "event_uuid" in self.kwargs:
|
|
|
|
self.eventproposal = get_object_or_404(
|
|
|
|
models.EventProposal, uuid=self.kwargs["event_uuid"], user=request.user
|
|
|
|
)
|
|
|
|
elif "speaker_uuid" in self.kwargs:
|
|
|
|
self.speakerproposal = get_object_or_404(
|
|
|
|
models.SpeakerProposal,
|
|
|
|
uuid=self.kwargs["speaker_uuid"],
|
|
|
|
user=request.user,
|
|
|
|
)
|
2018-05-23 21:28:27 +00:00
|
|
|
else:
|
|
|
|
# fuckery afoot
|
|
|
|
raise Http404
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
"""
|
|
|
|
Include the proposal in the template context
|
|
|
|
"""
|
|
|
|
context = super().get_context_data(**kwargs)
|
2019-06-16 12:32:24 +00:00
|
|
|
if hasattr(self, "eventproposal") and self.eventproposal:
|
|
|
|
context["eventproposal"] = self.eventproposal
|
2018-05-23 21:28:27 +00:00
|
|
|
else:
|
2019-06-16 12:32:24 +00:00
|
|
|
context["speakerproposal"] = self.speakerproposal
|
2018-05-23 21:28:27 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
"""
|
|
|
|
Return to the detail view of the proposal
|
|
|
|
"""
|
2019-06-16 12:32:24 +00:00
|
|
|
if hasattr(self, "eventproposal"):
|
2018-05-23 21:28:27 +00:00
|
|
|
return self.eventproposal.get_absolute_url()
|
|
|
|
else:
|
|
|
|
return self.speakerproposal.get_absolute_url()
|