Merge pull request #30 from normanjaeckel/SupportView_in_motion

New: Support view in motion
This commit is contained in:
Oskar Hahn 2012-10-28 07:19:10 -07:00
commit a100fd5d78
4 changed files with 51 additions and 35 deletions

View File

@ -258,25 +258,21 @@ 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))
# 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
"""
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:
# TODO: Don't do nothing but raise a precise exception for the view
pass
else:
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)
# 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
self.number is None) or
(self.submitter == user and self.number is None)):

View File

@ -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<motion_id>\d+)/support/$',
'support',
SupportView.as_view(support=True),
name='motion_support',
),
url(r'^(?P<motion_id>\d+)/unsupport/$',
'unsupport',
SupportView.as_view(support=False),
name='motion_unsupport',
),

View File

@ -41,7 +41,8 @@ from openslides.utils.pdf import stylesheet
from openslides.utils.template import Tab
from openslides.utils.utils import (template, permission_required,
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.config.models import config
@ -363,32 +364,51 @@ def reset(request, motion_id):
return redirect(reverse('motion_view', args=[motion_id]))
@permission_required('motion.can_support_motion')
@template('motion/view.html')
def support(request, motion_id):
class SupportView(SingleObjectMixin, QuestionMixin, RedirectView):
"""
support an motion.
Classed based view to support or unsupport a motion. Use
support=True or support=False in urls.py
"""
try:
Motion.objects.get(pk=motion_id).support(person=request.user)
messages.success(request, _("You have support the motion successfully.") )
except Motion.DoesNotExist:
pass
return redirect(reverse('motion_view', args=[motion_id]))
permission_required = 'motion.can_support_motion'
model = Motion
pk_url_kwarg = 'motion_id'
support = True
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')
@template('motion/view.html')
def unsupport(request, motion_id):
"""
unsupport an motion.
"""
try:
Motion.objects.get(pk=motion_id).unsupport(person=request.user)
messages.success(request, _("You have unsupport the motion successfully.") )
except Motion.DoesNotExist:
pass
return redirect(reverse('motion_view', args=[motion_id]))
def pre_redirect(self, request, *args, **kwargs):
allowed_actions = self.get_object().get_allowed_actions(request.user)
if self.support and not 'support' in allowed_actions:
messages.error(request, _('You can not support this motion.'))
elif not self.support and not 'unsupport' in allowed_actions:
messages.error(request, _('You can not unsupport this motion.'))
else:
super(SupportView, self).pre_redirect(request, *args, **kwargs)
def pre_post_redirect(self, request, *args, **kwargs):
motion = self.get_object()
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')

View File

@ -143,7 +143,7 @@ class QuestionMixin(object):
'option_fields': option_fields})
def pre_redirect(self, request, *args, **kwargs):
self.confirm_form(request, self.object)
self.confirm_form()
def pre_post_redirect(self, request, *args, **kwargs):
messages.success(request)