Merge pull request #30 from normanjaeckel/SupportView_in_motion
New: Support view in motion
This commit is contained in:
commit
a100fd5d78
@ -258,25 +258,21 @@ class Motion(models.Model, SlideMixin):
|
|||||||
"""
|
"""
|
||||||
if person == self.submitter:
|
if person == self.submitter:
|
||||||
# TODO: Use own Exception
|
# 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.')
|
'motion.')
|
||||||
if self.permitted is not None:
|
|
||||||
# TODO: Use own Exception
|
|
||||||
raise NameError('This motion is already permitted.')
|
|
||||||
if not self.is_supporter(person):
|
if not self.is_supporter(person):
|
||||||
MotionSupporter(motion=self, person=person).save()
|
MotionSupporter(motion=self, person=person).save()
|
||||||
self.writelog(_("Supporter: +%s") % (person))
|
self.writelog(_("Supporter: +%s") % (person))
|
||||||
|
# TODO: Raise a precise exception for the view in else-clause
|
||||||
|
|
||||||
def unsupport(self, person):
|
def unsupport(self, person):
|
||||||
"""
|
"""
|
||||||
remove a supporter from the list of supporters of the motion
|
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:
|
try:
|
||||||
object = self.motionsupporter_set.get(person=person).delete()
|
object = self.motionsupporter_set.get(person=person).delete()
|
||||||
except MotionSupporter.DoesNotExist:
|
except MotionSupporter.DoesNotExist:
|
||||||
|
# TODO: Don't do nothing but raise a precise exception for the view
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.writelog(_("Supporter: -%s") % (person))
|
self.writelog(_("Supporter: -%s") % (person))
|
||||||
@ -399,7 +395,7 @@ class Motion(models.Model, SlideMixin):
|
|||||||
|
|
||||||
# Check if the user can delete the motion (admin, manager, owner)
|
# Check if the user can delete the motion (admin, manager, owner)
|
||||||
# reworked as requiered in #100
|
# reworked as requiered in #100
|
||||||
if (user.has_perm("applicatoin.can_delete_all_motions") or
|
if (user.has_perm("motion.can_delete_all_motions") or
|
||||||
(user.has_perm("motion.can_manage_motion") and
|
(user.has_perm("motion.can_manage_motion") and
|
||||||
self.number is None) or
|
self.number is None) or
|
||||||
(self.submitter == user and self.number is None)):
|
(self.submitter == user and self.number is None)):
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
from django.conf.urls.defaults import url, patterns
|
from django.conf.urls.defaults import url, patterns
|
||||||
|
|
||||||
from openslides.motion.views import (MotionDelete, ViewPoll,
|
from openslides.motion.views import (MotionDelete, ViewPoll,
|
||||||
MotionPDF, MotionPollPDF, CreateAgendaItem)
|
MotionPDF, MotionPollPDF, CreateAgendaItem, SupportView)
|
||||||
|
|
||||||
urlpatterns = patterns('openslides.motion.views',
|
urlpatterns = patterns('openslides.motion.views',
|
||||||
url(r'^$',
|
url(r'^$',
|
||||||
@ -99,12 +99,12 @@ urlpatterns = patterns('openslides.motion.views',
|
|||||||
),
|
),
|
||||||
|
|
||||||
url(r'^(?P<motion_id>\d+)/support/$',
|
url(r'^(?P<motion_id>\d+)/support/$',
|
||||||
'support',
|
SupportView.as_view(support=True),
|
||||||
name='motion_support',
|
name='motion_support',
|
||||||
),
|
),
|
||||||
|
|
||||||
url(r'^(?P<motion_id>\d+)/unsupport/$',
|
url(r'^(?P<motion_id>\d+)/unsupport/$',
|
||||||
'unsupport',
|
SupportView.as_view(support=False),
|
||||||
name='motion_unsupport',
|
name='motion_unsupport',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@ from openslides.utils.pdf import stylesheet
|
|||||||
from openslides.utils.template import Tab
|
from openslides.utils.template import Tab
|
||||||
from openslides.utils.utils import (template, permission_required,
|
from openslides.utils.utils import (template, permission_required,
|
||||||
del_confirm_form, gen_confirm_form)
|
del_confirm_form, gen_confirm_form)
|
||||||
from openslides.utils.views import PDFView, RedirectView, DeleteView, FormView
|
from openslides.utils.views import (PDFView, RedirectView, DeleteView,
|
||||||
|
FormView, SingleObjectMixin, QuestionMixin)
|
||||||
from openslides.utils.person import get_person
|
from openslides.utils.person import get_person
|
||||||
|
|
||||||
from openslides.config.models import config
|
from openslides.config.models import config
|
||||||
@ -363,32 +364,51 @@ def reset(request, motion_id):
|
|||||||
return redirect(reverse('motion_view', args=[motion_id]))
|
return redirect(reverse('motion_view', args=[motion_id]))
|
||||||
|
|
||||||
|
|
||||||
@permission_required('motion.can_support_motion')
|
class SupportView(SingleObjectMixin, QuestionMixin, RedirectView):
|
||||||
@template('motion/view.html')
|
|
||||||
def support(request, motion_id):
|
|
||||||
"""
|
"""
|
||||||
support an motion.
|
Classed based view to support or unsupport a motion. Use
|
||||||
|
support=True or support=False in urls.py
|
||||||
"""
|
"""
|
||||||
try:
|
permission_required = 'motion.can_support_motion'
|
||||||
Motion.objects.get(pk=motion_id).support(person=request.user)
|
model = Motion
|
||||||
messages.success(request, _("You have support the motion successfully.") )
|
pk_url_kwarg = 'motion_id'
|
||||||
except Motion.DoesNotExist:
|
support = True
|
||||||
pass
|
|
||||||
return redirect(reverse('motion_view', args=[motion_id]))
|
|
||||||
|
|
||||||
|
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?')
|
||||||
|
|
||||||
@permission_required('motion.can_support_motion')
|
def pre_redirect(self, request, *args, **kwargs):
|
||||||
@template('motion/view.html')
|
allowed_actions = self.get_object().get_allowed_actions(request.user)
|
||||||
def unsupport(request, motion_id):
|
if self.support and not 'support' in allowed_actions:
|
||||||
"""
|
messages.error(request, _('You can not support this motion.'))
|
||||||
unsupport an motion.
|
elif not self.support and not 'unsupport' in allowed_actions:
|
||||||
"""
|
messages.error(request, _('You can not unsupport this motion.'))
|
||||||
try:
|
else:
|
||||||
Motion.objects.get(pk=motion_id).unsupport(person=request.user)
|
super(SupportView, self).pre_redirect(request, *args, **kwargs)
|
||||||
messages.success(request, _("You have unsupport the motion successfully.") )
|
|
||||||
except Motion.DoesNotExist:
|
def pre_post_redirect(self, request, *args, **kwargs):
|
||||||
pass
|
motion = self.get_object()
|
||||||
return redirect(reverse('motion_view', args=[motion_id]))
|
if self.get_answer().lower() == 'yes':
|
||||||
|
if self.support:
|
||||||
|
motion.support(person=request.user)
|
||||||
|
self.success_message = _("You have supported this motion successfully.")
|
||||||
|
else:
|
||||||
|
motion.unsupport(person=request.user)
|
||||||
|
self.success_message = _("You have unsupported this motion successfully.")
|
||||||
|
messages.success(request, self.success_message)
|
||||||
|
|
||||||
|
def get_redirect_url(self, **kwargs):
|
||||||
|
return reverse('motion_view', args=[kwargs[self.pk_url_kwarg]])
|
||||||
|
|
||||||
|
def get_answer_url(self):
|
||||||
|
if self.support:
|
||||||
|
answer_url = 'motion_support'
|
||||||
|
else:
|
||||||
|
answer_url = 'motion_unsupport'
|
||||||
|
return reverse(answer_url, args=[self.kwargs[self.pk_url_kwarg]])
|
||||||
|
|
||||||
|
|
||||||
@permission_required('motion.can_manage_motion')
|
@permission_required('motion.can_manage_motion')
|
||||||
|
@ -143,7 +143,7 @@ class QuestionMixin(object):
|
|||||||
'option_fields': option_fields})
|
'option_fields': option_fields})
|
||||||
|
|
||||||
def pre_redirect(self, request, *args, **kwargs):
|
def pre_redirect(self, request, *args, **kwargs):
|
||||||
self.confirm_form(request, self.object)
|
self.confirm_form()
|
||||||
|
|
||||||
def pre_post_redirect(self, request, *args, **kwargs):
|
def pre_post_redirect(self, request, *args, **kwargs):
|
||||||
messages.success(request)
|
messages.success(request)
|
||||||
|
Loading…
Reference in New Issue
Block a user