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.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
@ -254,15 +254,19 @@ class Motion(SlideMixin, models.Model):
"""
Add a Supporter to the list of supporters of the motion.
"""
if self.state.support:
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
else:
raise WorkflowError("You can not support a motion in state %s" % self.state.name)
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.state.support:
try:
self.supporter.filter(person=person).delete()
except MotionSupporter.DoesNotExist:
@ -270,16 +274,21 @@ class Motion(SlideMixin, models.Model):
pass
#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):
"""
Create a new poll for this motion
"""
# TODO: auto increment the poll_number in the Database
if self.state.poll:
poll_number = self.polls.aggregate(Max('poll_number'))['poll_number__max'] or 0
poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1)
poll.set_options()
return poll
else:
raise WorkflowError("You can not create a poll in state %s" % self.state.name)
def get_state(self):
"""

View File

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