Block supporting, unsupporting and creation of poll in some states

This commit is contained in:
Oskar Hahn 2013-02-01 16:44:06 +01:00
parent fb82a1787b
commit ac41a02ac5
2 changed files with 29 additions and 17 deletions

View File

@ -30,7 +30,7 @@ from openslides.projector.api import register_slidemodel
from openslides.projector.models import SlideMixin from openslides.projector.models import SlideMixin
from openslides.agenda.models import Item from openslides.agenda.models import Item
from .workflow import motion_workflow_choices, get_state, State from .workflow import motion_workflow_choices, get_state, State, WorkflowError
# TODO: Save submitter and supporter in the same table # TODO: Save submitter and supporter in the same table
@ -254,32 +254,41 @@ class Motion(SlideMixin, models.Model):
""" """
Add a Supporter to the list of supporters of the motion. Add a Supporter to the list of supporters of the motion.
""" """
if not self.is_supporter(person): if self.state.support:
MotionSupporter(motion=self, person=person).save() if not self.is_supporter(person):
#self.writelog(_("Supporter: +%s") % (person)) MotionSupporter(motion=self, person=person).save()
# TODO: Raise a precise exception for the view in else-clause #self.writelog(_("Supporter: +%s") % (person))
# TODO: Raise a precise exception for the view in else-clause
else:
raise WorkflowError("You can not support a motion in state %s" % self.state.name)
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
""" """
try: if self.state.support:
self.supporter.filter(person=person).delete() try:
except MotionSupporter.DoesNotExist: self.supporter.filter(person=person).delete()
# TODO: Don't do nothing but raise a precise exception for the view except MotionSupporter.DoesNotExist:
pass # TODO: Don't do nothing but raise a precise exception for the view
#else: pass
#self.writelog(_("Supporter: -%s") % (person)) #else:
#self.writelog(_("Supporter: -%s") % (person))
else:
raise WorkflowError("You can not unsupport a motion in state %s" % self.state.name)
def create_poll(self): def create_poll(self):
""" """
Create a new poll for this motion Create a new poll for this motion
""" """
# TODO: auto increment the poll_number in the Database # TODO: auto increment the poll_number in the Database
poll_number = self.polls.aggregate(Max('poll_number'))['poll_number__max'] or 0 if self.state.poll:
poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1) poll_number = self.polls.aggregate(Max('poll_number'))['poll_number__max'] or 0
poll.set_options() poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1)
return poll poll.set_options()
return poll
else:
raise WorkflowError("You can not create a poll in state %s" % self.state.name)
def get_state(self): def get_state(self):
""" """

View File

@ -18,6 +18,9 @@ class State(object):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
class WorkflowError(Exception):
pass
def motion_workflow_choices(): def motion_workflow_choices():
for workflow in settings.MOTION_WORKFLOW: for workflow in settings.MOTION_WORKFLOW: