From 2e41dcdefea4c765542c4123ef95a0a33d242bae Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 25 Oct 2012 10:15:41 +0200 Subject: [PATCH] Fixt problems with the permission of supporting and unsupporting a motion Ticket #377 --- openslides/motion/models.py | 8 +------- openslides/motion/urls.py | 6 +++--- openslides/motion/views.py | 30 ++++++++++++++++++++++++------ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/openslides/motion/models.py b/openslides/motion/models.py index 3f5635a19..71a6aa80f 100644 --- a/openslides/motion/models.py +++ b/openslides/motion/models.py @@ -258,11 +258,8 @@ class Motion(models.Model, SlideMixin): """ if person == self.submitter: # TODO: Use own Exception - raise NameError('Supporter can not be the submitter of a ' \ + raise NameError('Supporter can not be the submitter of a ' 'motion.') - if self.permitted is not None: - # TODO: Use own Exception - raise NameError('This motion is already permitted.') if not self.is_supporter(person): MotionSupporter(motion=self, person=person).save() self.writelog(_("Supporter: +%s") % (person)) @@ -272,9 +269,6 @@ class Motion(models.Model, SlideMixin): """ remove a supporter from the list of supporters of the motion """ - if self.permitted is not None: - # TODO: Use own Exception - raise NameError('This motion is already permitted.') try: object = self.motionsupporter_set.get(person=person).delete() except MotionSupporter.DoesNotExist: diff --git a/openslides/motion/urls.py b/openslides/motion/urls.py index 55543d615..6c7956c60 100644 --- a/openslides/motion/urls.py +++ b/openslides/motion/urls.py @@ -13,7 +13,7 @@ from django.conf.urls.defaults import url, patterns from openslides.motion.views import (MotionDelete, ViewPoll, - MotionPDF, MotionPollPDF, CreateAgendaItem) + MotionPDF, MotionPollPDF, CreateAgendaItem, SupportView) urlpatterns = patterns('openslides.motion.views', url(r'^$', @@ -99,12 +99,12 @@ urlpatterns = patterns('openslides.motion.views', ), url(r'^(?P\d+)/support/$', - 'support', + SupportView.as_view(unsupport=False, answer_url='support/'), name='motion_support', ), url(r'^(?P\d+)/unsupport/$', - 'unsupport', + SupportView.as_view(unsupport=True, answer_url='unsupport/'), name='motion_unsupport', ), diff --git a/openslides/motion/views.py b/openslides/motion/views.py index 1b4166870..0ef1f140f 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -381,14 +381,32 @@ class SupportView(SingleObjectMixin, QuestionMixin, RedirectView): return _('Do you really want to unsupport this motion?') def pre_post_redirect(self, request, *args, **kwargs): - if self.get_answer().lower() == 'yes': - if not self.unsupport: - self.get_object().support(person=request.user) - self.success_message = _("You have supported this motion successfully.") + motion = self.get_object() + allowed_actions = motion.get_allowed_actions(request.user) + if not self.get_answer().lower() == 'yes': + return + if not self.unsupport: + if 'support' in allowed_actions: + motion.support(person=request.user) + messages.success( + request, + _("You have supported this motion successfully.")) + else: + messages.error( + request, + _('You can not support this motion.')) + else: + if 'unsupport' in allowed_actions: self.get_object().unsupport(person=request.user) - self.success_message = _("You have unsupported this motion successfully.") - messages.success(request, self.success_message) + messages.success( + request, + _("You have unsupported this motion successfully.")) + else: + messages.error( + request, + _('You can not support this motion.')) + def get_redirect_url(self, **kwargs): return reverse('motion_view', args=[kwargs[self.pk_url_kwarg]])