Motion Identifier

This commit is contained in:
Oskar Hahn 2013-03-12 22:03:56 +01:00
parent 31ba70efd1
commit 9cd69f59e0
5 changed files with 78 additions and 4 deletions

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
openslides.motion openslides.motion

View File

@ -16,7 +16,7 @@
from datetime import datetime from datetime import datetime
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models from django.db import models, IntegrityError
from django.db.models import Max from django.db.models import Max
from django.dispatch import receiver from django.dispatch import receiver
from django.utils import formats from django.utils import formats
@ -65,6 +65,12 @@ class Motion(SlideMixin, models.Model):
unique=True) unique=True)
"""A string as human readable identifier for the motion.""" """A string as human readable identifier for the motion."""
identifier_number = models.IntegerField(null=True)
"""Counts the number of the motion in one category.
Needed to find the next free motion-identifier.
"""
category = models.ForeignKey('Category', null=True, blank=True) category = models.ForeignKey('Category', null=True, blank=True)
"""ForeignKey to one category of motions.""" """ForeignKey to one category of motions."""
@ -170,6 +176,29 @@ class Motion(SlideMixin, models.Model):
if link == 'delete': if link == 'delete':
return reverse('motion_delete', args=[str(self.id)]) return reverse('motion_delete', args=[str(self.id)])
def set_identifier(self):
# TODO: into the config-tab
config['motion_identifier'] = ('manuell', 'category', 'all')[0]
number = Motion.objects.all().aggregate(Max('identifier_number'))['identifier_number__max'] or 0
if self.category is not None:
prefix = self.category.prefix + ' '
else:
prefix = ''
while True:
number += 1
self.identifier = '%s%d' % (prefix, number)
try:
self.save()
except IntegrityError:
continue
else:
self.number = number
self.save()
break
def get_title(self): def get_title(self):
"""Get the title of the motion. """Get the title of the motion.
@ -346,6 +375,18 @@ class Motion(SlideMixin, models.Model):
else: else:
raise WorkflowError('You can not create a poll in state %s.' % self.state.name) raise WorkflowError('You can not create a poll in state %s.' % self.state.name)
def set_state(self, state):
"""Set the state of the motion.
State can be the id of a state object or a state object.
"""
if type(state) is int:
state = State.objects.get(pk=state)
if state.set_identifier:
self.set_identifier()
self.state = state
def reset_state(self): def reset_state(self):
"""Set the state to the default state. If the motion is new, it chooses the default workflow from config.""" """Set the state to the default state. If the motion is new, it chooses the default workflow from config."""
if self.state: if self.state:
@ -692,6 +733,9 @@ class State(models.Model):
dont_set_new_version_active = models.BooleanField(default=False) dont_set_new_version_active = models.BooleanField(default=False)
"""If true, new versions are not automaticly set active.""" """If true, new versions are not automaticly set active."""
set_identifier = models.BooleanField(default=False)
"""If true, the motion get a identifier if the state change to this one."""
def __unicode__(self): def __unicode__(self):
"""Returns the name of the state.""" """Returns the name of the state."""
return self.name return self.name

View File

@ -11,8 +11,8 @@
{{ motion.title }} {{ motion.title }}
<br> <br>
<small> <small>
{% if motion.number != None %} {% if motion.identifier != None %}
{% trans "Motion" %} {{ motion.number }}, {% trans "Motion" %} {{ motion.identifier }},
{% else %} {% else %}
<i>[{% trans "no number" %}]</i>, <i>[{% trans "no number" %}]</i>,
{% endif %} {% endif %}

View File

@ -40,6 +40,11 @@ urlpatterns = patterns('openslides.motion.views',
name='motion_delete', name='motion_delete',
), ),
url(r'^(?P<pk>\d+)/set_identifier',
'set_identifier',
name='motion_set_identifier',
),
url(r'^(?P<pk>\d+)/version/(?P<version_number>\d+)/$', url(r'^(?P<pk>\d+)/version/(?P<version_number>\d+)/$',
'motion_detail', 'motion_detail',
name='motion_version_detail', name='motion_version_detail',

View File

@ -230,6 +230,30 @@ class VersionRejectView(GetVersionMixin, SingleObjectMixin, QuestionMixin, Redir
version_reject = VersionRejectView.as_view() version_reject = VersionRejectView.as_view()
class SetIdentifierView(SingleObjectMixin, RedirectView):
"""Set the identifier of the motion.
See motion.set_identifier for more informations
"""
permission_required = 'motion.can_manage_motion'
model = Motion
url_name = 'motion_detail'
def get(self, request, *args, **kwargs):
"""Set self.object to a motion."""
self.object = self.get_object()
return super(SetIdentifierView, self).get(request, *args, **kwargs)
def pre_redirect(self, request, *args, **kwargs):
"""Set the identifier."""
self.object.set_identifier()
def get_url_name_args(self):
return [self.object.id]
set_identifier = SetIdentifierView.as_view()
class SupportView(SingleObjectMixin, QuestionMixin, RedirectView): class SupportView(SingleObjectMixin, QuestionMixin, RedirectView):
"""View to support or unsupport a motion. """View to support or unsupport a motion.
@ -401,7 +425,7 @@ class MotionSetStateView(SingleObjectMixin, RedirectView):
if self.reset: if self.reset:
self.object.reset_state() self.object.reset_state()
else: else:
self.object.state = State.objects.get(pk=kwargs['state']) self.object.set_state(int(kwargs['state']))
except WorkflowError, e: # TODO: Is a WorkflowError still possible here? except WorkflowError, e: # TODO: Is a WorkflowError still possible here?
messages.error(request, e) messages.error(request, e)
else: else: