set identifier
This commit is contained in:
parent
304887e8f3
commit
b2c888b151
@ -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(
|
||||
|
@ -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.
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
{% block content %}
|
||||
<h1>
|
||||
{{ motion.title }}
|
||||
{{ motion.title }} {{ motion.category }}
|
||||
<br>
|
||||
<small>
|
||||
{% if motion.identifier != None %}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user