From b2c888b151693a040c80aeb1df9240453139e6ba Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Tue, 12 Mar 2013 23:35:08 +0100 Subject: [PATCH] set identifier --- openslides/motion/forms.py | 6 +++++ openslides/motion/models.py | 22 +++++++++++++------ .../templates/motion/motion_detail.html | 2 +- openslides/motion/views.py | 15 ++++++++++++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/openslides/motion/forms.py b/openslides/motion/forms.py index 1ddac7b97..7b81d6524 100644 --- a/openslides/motion/forms.py +++ b/openslides/motion/forms.py @@ -96,6 +96,12 @@ class MotionCategoryMixin(forms.ModelForm): 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): """Form for the configuration tab of OpenSlides.""" motion_min_supporters = forms.IntegerField( diff --git a/openslides/motion/models.py b/openslides/motion/models.py index 73d18d63c..a1b13b950 100644 --- a/openslides/motion/models.py +++ b/openslides/motion/models.py @@ -37,6 +37,10 @@ from openslides.agenda.models import Item from .exceptions import MotionError, WorkflowError +# TODO: into the config-tab +config['motion_identifier'] = ('manually', 'per_category', 'serially_numbered')[0] + + class Motion(SlideMixin, models.Model): """The Motion Class. @@ -177,14 +181,19 @@ class Motion(SlideMixin, models.Model): 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 + ' ' + if config['motion_identifier'] == 'manually': + # Do not set an identifier. + return + elif config['motion_identifier'] == 'per_category': + motions = Motion.objects.filter(category=self.category) else: + motions = Motion.objects.all() + + number = motions.aggregate(Max('identifier_number'))['identifier_number__max'] or 0 + if self.category is None: prefix = '' + else: + prefix = self.category.prefix + ' ' while True: number += 1 @@ -198,7 +207,6 @@ class Motion(SlideMixin, models.Model): self.save() break - def get_title(self): """Get the title of the motion. diff --git a/openslides/motion/templates/motion/motion_detail.html b/openslides/motion/templates/motion/motion_detail.html index c9a8b63aa..12d26fba3 100644 --- a/openslides/motion/templates/motion/motion_detail.html +++ b/openslides/motion/templates/motion/motion_detail.html @@ -8,7 +8,7 @@ {% block content %}

- {{ motion.title }} + {{ motion.title }} {{ motion.category }}
{% if motion.identifier != None %} diff --git a/openslides/motion/views.py b/openslides/motion/views.py index 6d4d40cc8..8af3fef2c 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -35,7 +35,8 @@ from openslides.agenda.models import Item from .models import (Motion, MotionSubmitter, MotionSupporter, MotionPoll, MotionVersion, State, WorkflowError, Category) from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin, - MotionDisableVersioningMixin, ConfigForm, MotionCategoryMixin) + MotionDisableVersioningMixin, ConfigForm, MotionCategoryMixin, + MotionIdentifierMixin) from .pdf import motions_to_pdf, motion_to_pdf @@ -98,6 +99,16 @@ class MotionMixin(object): except KeyError: 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): """Save the submitter an the supporter so the motion.""" super(MotionMixin, self).post_save(form) @@ -127,6 +138,8 @@ class MotionMixin(object): form_classes.append(MotionCategoryMixin) if config['motion_min_supporters'] > 0: form_classes.append(MotionSupporterMixin) + if config['motion_identifier'] == 'manually': + form_classes.append(MotionIdentifierMixin) if self.object: if config['motion_allow_disable_versioning'] and self.object.state.versioning: form_classes.append(MotionDisableVersioningMixin)