set identifier

This commit is contained in:
Oskar Hahn 2013-03-12 23:35:08 +01:00
parent 304887e8f3
commit b2c888b151
4 changed files with 36 additions and 9 deletions

View File

@ -96,6 +96,12 @@ class MotionCategoryMixin(forms.ModelForm):
category = forms.ModelChoiceField(queryset=Category.objects.all(), required=False) category = forms.ModelChoiceField(queryset=Category.objects.all(), required=False)
class MotionIdentifierMixin(forms.ModelForm):
"""Mixin to let the user choose the identifier for the motion."""
identifier = forms.CharField(required=False)
class ConfigForm(CssClassMixin, forms.Form): class ConfigForm(CssClassMixin, forms.Form):
"""Form for the configuration tab of OpenSlides.""" """Form for the configuration tab of OpenSlides."""
motion_min_supporters = forms.IntegerField( motion_min_supporters = forms.IntegerField(

View File

@ -37,6 +37,10 @@ from openslides.agenda.models import Item
from .exceptions import MotionError, WorkflowError from .exceptions import MotionError, WorkflowError
# TODO: into the config-tab
config['motion_identifier'] = ('manually', 'per_category', 'serially_numbered')[0]
class Motion(SlideMixin, models.Model): class Motion(SlideMixin, models.Model):
"""The Motion Class. """The Motion Class.
@ -177,14 +181,19 @@ class Motion(SlideMixin, models.Model):
return reverse('motion_delete', args=[str(self.id)]) return reverse('motion_delete', args=[str(self.id)])
def set_identifier(self): def set_identifier(self):
# TODO: into the config-tab if config['motion_identifier'] == 'manually':
config['motion_identifier'] = ('manuell', 'category', 'all')[0] # Do not set an identifier.
return
number = Motion.objects.all().aggregate(Max('identifier_number'))['identifier_number__max'] or 0 elif config['motion_identifier'] == 'per_category':
if self.category is not None: motions = Motion.objects.filter(category=self.category)
prefix = self.category.prefix + ' '
else: else:
motions = Motion.objects.all()
number = motions.aggregate(Max('identifier_number'))['identifier_number__max'] or 0
if self.category is None:
prefix = '' prefix = ''
else:
prefix = self.category.prefix + ' '
while True: while True:
number += 1 number += 1
@ -198,7 +207,6 @@ class Motion(SlideMixin, models.Model):
self.save() self.save()
break break
def get_title(self): def get_title(self):
"""Get the title of the motion. """Get the title of the motion.

View File

@ -8,7 +8,7 @@
{% block content %} {% block content %}
<h1> <h1>
{{ motion.title }} {{ motion.title }} {{ motion.category }}
<br> <br>
<small> <small>
{% if motion.identifier != None %} {% if motion.identifier != None %}

View File

@ -35,7 +35,8 @@ from openslides.agenda.models import Item
from .models import (Motion, MotionSubmitter, MotionSupporter, MotionPoll, from .models import (Motion, MotionSubmitter, MotionSupporter, MotionPoll,
MotionVersion, State, WorkflowError, Category) MotionVersion, State, WorkflowError, Category)
from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin, from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin,
MotionDisableVersioningMixin, ConfigForm, MotionCategoryMixin) MotionDisableVersioningMixin, ConfigForm, MotionCategoryMixin,
MotionIdentifierMixin)
from .pdf import motions_to_pdf, motion_to_pdf from .pdf import motions_to_pdf, motion_to_pdf
@ -98,6 +99,16 @@ class MotionMixin(object):
except KeyError: except KeyError:
pass pass
try:
self.object.category = form.cleaned_data['category']
except KeyError:
pass
try:
self.object.identifier = form.cleaned_data['identifier']
except KeyError:
pass
def post_save(self, form): def post_save(self, form):
"""Save the submitter an the supporter so the motion.""" """Save the submitter an the supporter so the motion."""
super(MotionMixin, self).post_save(form) super(MotionMixin, self).post_save(form)
@ -127,6 +138,8 @@ class MotionMixin(object):
form_classes.append(MotionCategoryMixin) form_classes.append(MotionCategoryMixin)
if config['motion_min_supporters'] > 0: if config['motion_min_supporters'] > 0:
form_classes.append(MotionSupporterMixin) form_classes.append(MotionSupporterMixin)
if config['motion_identifier'] == 'manually':
form_classes.append(MotionIdentifierMixin)
if self.object: if self.object:
if config['motion_allow_disable_versioning'] and self.object.state.versioning: if config['motion_allow_disable_versioning'] and self.object.state.versioning:
form_classes.append(MotionDisableVersioningMixin) form_classes.append(MotionDisableVersioningMixin)