Merge pull request #31 from normanjaeckel/master

Fix SupportView
This commit is contained in:
Oskar Hahn 2012-10-28 09:48:47 -07:00
commit 76534cf287

View File

@ -380,18 +380,28 @@ class SupportView(SingleObjectMixin, QuestionMixin, RedirectView):
else: else:
return _('Do you really want to unsupport this motion?') return _('Do you really want to unsupport this motion?')
def pre_redirect(self, request, *args, **kwargs): def check_allowed_actions(self, request):
"""
Checks whether request.user can support or unsupport the motion.
Returns True or False.
"""
allowed_actions = self.get_object().get_allowed_actions(request.user) allowed_actions = self.get_object().get_allowed_actions(request.user)
if self.support and not 'support' in allowed_actions: if self.support and not 'support' in allowed_actions:
messages.error(request, _('You can not support this motion.')) messages.error(request, _('You can not support this motion.'))
return False
elif not self.support and not 'unsupport' in allowed_actions: elif not self.support and not 'unsupport' in allowed_actions:
messages.error(request, _('You can not unsupport this motion.')) messages.error(request, _('You can not unsupport this motion.'))
return False
else: else:
return True
def pre_redirect(self, request, *args, **kwargs):
if self.check_allowed_actions(request):
super(SupportView, self).pre_redirect(request, *args, **kwargs) super(SupportView, self).pre_redirect(request, *args, **kwargs)
def pre_post_redirect(self, request, *args, **kwargs): def pre_post_redirect(self, request, *args, **kwargs):
motion = self.get_object() motion = self.get_object()
if self.get_answer().lower() == 'yes': if self.get_answer().lower() == 'yes' and self.check_allowed_actions(request):
if self.support: if self.support:
motion.support(person=request.user) motion.support(person=request.user)
self.success_message = _("You have supported this motion successfully.") self.success_message = _("You have supported this motion successfully.")