From dd23490c0179a1230ce78f180c40b76df00fe395 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sat, 18 Mar 2017 16:22:16 +0100 Subject: [PATCH] add mixin to prevent adding and editing user submitted speaker and event proposals --- src/program/mixins.py | 11 +++++++++++ src/program/views.py | 14 +++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/program/mixins.py b/src/program/mixins.py index 02be79a3..20cc04e8 100644 --- a/src/program/mixins.py +++ b/src/program/mixins.py @@ -7,6 +7,17 @@ import sys, mimetypes from django.http import Http404, HttpResponse +class EnsureCFSOpenMixin(SingleObjectMixin): + def dispatch(self, request, *args, **kwargs): + # do not permit editing if call for speakers is not open + if not self.get_object().camp.call_for_speakers_open: + messages.error(request, "The Call for Speakers is not open.") + return redirect(reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})) + + # alright, continue with the request + return super().dispatch(request, *args, **kwargs) + + class CreateProposalMixin(SingleObjectMixin): def form_valid(self, form): # set camp and user before saving diff --git a/src/program/views.py b/src/program/views.py index 9269c176..d19c38ad 100644 --- a/src/program/views.py +++ b/src/program/views.py @@ -9,7 +9,7 @@ from django.contrib import messages from django.shortcuts import redirect from django.urls import reverse from camps.mixins import CampViewMixin -from .mixins import CreateProposalMixin, EnsureUnapprovedProposalMixin, EnsureUserOwnsProposalMixin, EnsureWritableCampMixin, PictureViewMixin +from .mixins import CreateProposalMixin, EnsureUnapprovedProposalMixin, EnsureUserOwnsProposalMixin, EnsureWritableCampMixin, PictureViewMixin, EnsureCFSOpenMixin from . import models import datetime, os @@ -33,7 +33,7 @@ class ProposalListView(LoginRequiredMixin, CampViewMixin, ListView): return context -class SpeakerProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposalMixin, EnsureWritableCampMixin, CreateView): +class SpeakerProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, CreateView): model = models.SpeakerProposal fields = ['name', 'biography', 'picture_small', 'picture_large'] template_name = 'speakerproposal_form.html' @@ -42,7 +42,7 @@ class SpeakerProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposa return reverse('proposal_list', kwargs={'camp_slug': self.camp.slug}) -class SpeakerProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, UpdateView): +class SpeakerProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView): model = models.SpeakerProposal fields = ['name', 'biography', 'picture_small', 'picture_large'] template_name = 'speakerproposal_form.html' @@ -57,7 +57,7 @@ class SpeakerProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwn return super().form_valid(form) -class SpeakerProposalSubmitView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, UpdateView): +class SpeakerProposalSubmitView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView): model = models.SpeakerProposal fields = [] template_name = 'speakerproposal_submit.html' @@ -90,7 +90,7 @@ class SpeakerProposalPictureView(LoginRequiredMixin, CampViewMixin, EnsureUserOw return response -class EventProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposalMixin, EnsureWritableCampMixin, CreateView): +class EventProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, CreateView): model = models.EventProposal fields = ['title', 'abstract', 'event_type', 'speakers'] template_name = 'eventproposal_form.html' @@ -102,7 +102,7 @@ class EventProposalCreateView(LoginRequiredMixin, CampViewMixin, CreateProposalM return context -class EventProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, UpdateView): +class EventProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView): model = models.EventProposal fields = ['title', 'abstract', 'event_type', 'speakers'] template_name = 'eventproposal_form.html' @@ -117,7 +117,7 @@ class EventProposalUpdateView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsP return super().form_valid(form) -class EventProposalSubmitView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, UpdateView): +class EventProposalSubmitView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsProposalMixin, EnsureUnapprovedProposalMixin, EnsureWritableCampMixin, EnsureCFSOpenMixin, UpdateView): model = models.EventProposal fields = [] template_name = 'eventproposal_submit.html'