Let the user support and unsupport the motion
This commit is contained in:
parent
7bcfa16737
commit
d911e311d6
@ -240,6 +240,33 @@ class Motion(SlideMixin, models.Model):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
return self.new_version
|
return self.new_version
|
||||||
|
|
||||||
|
def is_supporter(self, person):
|
||||||
|
try:
|
||||||
|
return self.supporter.filter(person=person).exists()
|
||||||
|
except AttributeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def support(self, person):
|
||||||
|
"""
|
||||||
|
Add a Supporter to the list of supporters of the motion.
|
||||||
|
"""
|
||||||
|
if not self.is_supporter(person):
|
||||||
|
MotionSupporter(motion=self, person=person).save()
|
||||||
|
#self.writelog(_("Supporter: +%s") % (person))
|
||||||
|
# TODO: Raise a precise exception for the view in else-clause
|
||||||
|
|
||||||
|
def unsupport(self, person):
|
||||||
|
"""
|
||||||
|
remove a supporter from the list of supporters of the motion
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.supporter.filter(person=person).delete()
|
||||||
|
except MotionSupporter.DoesNotExist:
|
||||||
|
# TODO: Don't do nothing but raise a precise exception for the view
|
||||||
|
pass
|
||||||
|
#else:
|
||||||
|
#self.writelog(_("Supporter: -%s") % (person))
|
||||||
|
|
||||||
|
|
||||||
class MotionVersion(models.Model):
|
class MotionVersion(models.Model):
|
||||||
title = models.CharField(max_length=255, verbose_name=ugettext_lazy("Title"))
|
title = models.CharField(max_length=255, verbose_name=ugettext_lazy("Title"))
|
||||||
|
@ -37,4 +37,14 @@ urlpatterns = patterns('openslides.motion.views',
|
|||||||
'motion_detail',
|
'motion_detail',
|
||||||
name='motion_version_detail',
|
name='motion_version_detail',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
url(r'^(?P<pk>\d+)/support/$',
|
||||||
|
'motion_support',
|
||||||
|
name='motion_support',
|
||||||
|
),
|
||||||
|
|
||||||
|
url(r'^(?P<pk>\d+)/unsupport/$',
|
||||||
|
'motion_unsupport',
|
||||||
|
name='motion_unsupport',
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
@ -22,7 +22,7 @@ from django.http import Http404
|
|||||||
from openslides.utils.pdf import stylesheet
|
from openslides.utils.pdf import stylesheet
|
||||||
from openslides.utils.views import (
|
from openslides.utils.views import (
|
||||||
TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView,
|
TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView,
|
||||||
DetailView, ListView, FormView)
|
DetailView, ListView, FormView, QuestionMixin)
|
||||||
from openslides.utils.template import Tab
|
from openslides.utils.template import Tab
|
||||||
from openslides.utils.utils import html_strong
|
from openslides.utils.utils import html_strong
|
||||||
from openslides.projector.api import get_active_slide
|
from openslides.projector.api import get_active_slide
|
||||||
@ -121,6 +121,65 @@ class MotionUpdateView(MotionMixin, UpdateView):
|
|||||||
motion_edit = MotionUpdateView.as_view()
|
motion_edit = MotionUpdateView.as_view()
|
||||||
|
|
||||||
|
|
||||||
|
class SupportView(SingleObjectMixin, QuestionMixin, RedirectView):
|
||||||
|
"""
|
||||||
|
Classed based view to support or unsupport a motion. Use
|
||||||
|
support=True or support=False in urls.py
|
||||||
|
"""
|
||||||
|
permission_required = 'motion.can_support_motion'
|
||||||
|
model = Motion
|
||||||
|
support = True
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
self.object = self.get_object()
|
||||||
|
return super(SupportView, self).get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def check_allowed_actions(self, request):
|
||||||
|
"""
|
||||||
|
Checks whether request.user can support or unsupport the motion.
|
||||||
|
Returns True or False.
|
||||||
|
"""
|
||||||
|
return True #TODO
|
||||||
|
allowed_actions = self.object.get_allowed_actions(request.user)
|
||||||
|
if self.support and not 'support' in allowed_actions:
|
||||||
|
messages.error(request, _('You can not support this motion.'))
|
||||||
|
return False
|
||||||
|
elif not self.support and not 'unsupport' in allowed_actions:
|
||||||
|
messages.error(request, _('You can not unsupport this motion.'))
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def pre_redirect(self, request, *args, **kwargs):
|
||||||
|
if self.check_allowed_actions(request):
|
||||||
|
super(SupportView, self).pre_redirect(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_question(self):
|
||||||
|
if self.support:
|
||||||
|
return _('Do you really want to support this motion?')
|
||||||
|
else:
|
||||||
|
return _('Do you really want to unsupport this motion?')
|
||||||
|
|
||||||
|
def case_yes(self):
|
||||||
|
if self.check_allowed_actions(self.request):
|
||||||
|
if self.support:
|
||||||
|
self.object.support(person=self.request.user)
|
||||||
|
else:
|
||||||
|
self.object.unsupport(person=self.request.user)
|
||||||
|
|
||||||
|
def get_success_message(self):
|
||||||
|
if self.support:
|
||||||
|
return _("You have supported this motion successfully.")
|
||||||
|
else:
|
||||||
|
return _("You have unsupported this motion successfully.")
|
||||||
|
|
||||||
|
def get_redirect_url(self, **kwargs):
|
||||||
|
return self.object.get_absolute_url()
|
||||||
|
|
||||||
|
motion_support = SupportView.as_view(support=True)
|
||||||
|
motion_unsupport = SupportView.as_view(support=False)
|
||||||
|
|
||||||
|
|
||||||
class Config(FormView):
|
class Config(FormView):
|
||||||
permission_required = 'config.can_manage_config'
|
permission_required = 'config.can_manage_config'
|
||||||
form_class = ConfigForm
|
form_class = ConfigForm
|
||||||
|
Loading…
Reference in New Issue
Block a user