From 87e42cf9f85720aa9f260405f9540afd4719bd1a Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 26 Jan 2013 17:09:13 +0100 Subject: [PATCH] Let the user choose if the motion should have a new version via config or form --- openslides/motion/forms.py | 17 ++++++++++------- openslides/motion/models.py | 4 ++-- openslides/motion/signals.py | 2 +- openslides/motion/views.py | 16 +++++++++++----- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/openslides/motion/forms.py b/openslides/motion/forms.py index 559317556..66307761a 100644 --- a/openslides/motion/forms.py +++ b/openslides/motion/forms.py @@ -61,9 +61,9 @@ class MotionSupporterMixin(forms.ModelForm): super(MotionSupporterMixin, self).__init__(*args, **kwargs) -class MotionTrivialChangesMixin(forms.ModelForm): - trivial_change = forms.BooleanField( - required=False, label=_("Trivial change"), +class MotionCreateNewVersionMixin(forms.ModelForm): + new_version = forms.BooleanField( + required=False, label=_("Create new version"), initial=True, help_text=_("Trivial changes don't create a new version.")) @@ -108,9 +108,12 @@ class ConfigForm(forms.Form, CssClassMixin): label=_("Preamble text for PDF document (all motions)") ) - motion_allow_trivial_change = forms.BooleanField( - label=_("Allow trivial changes"), - help_text=_('Warning: Trivial changes undermine the motions ' - 'autorisation system.'), + motion_create_new_version = forms.ChoiceField( + widget=forms.Select(), + label=_("Create new versions"), required=False, + choices=( + ('ALLWASY_CREATE_NEW_VERSION', _('create allways a new versions')), + ('NEVER_CREATE_NEW_VERSION', _('create never a new version')), + ('ASK_USER', _('Let the user choose if he wants to create a new version'))) ) diff --git a/openslides/motion/models.py b/openslides/motion/models.py index 600a5c59a..279276f8d 100644 --- a/openslides/motion/models.py +++ b/openslides/motion/models.py @@ -94,8 +94,8 @@ class Motion(SlideMixin, models.Model): else: new_data = False - need_new_version = True # TODO: Do we need a new version (look in config) - if hasattr(self, '_version') or (new_data and need_new_version): + need_new_version = config['motion_create_new_version'] == 'ALLWASY_CREATE_NEW_VERSION' + if hasattr(self, '_new_version') or (new_data and need_new_version): version = self.new_version del self._new_version version.motion = self # Test if this line is realy neccessary. diff --git a/openslides/motion/signals.py b/openslides/motion/signals.py index b73637485..c9b1ece36 100644 --- a/openslides/motion/signals.py +++ b/openslides/motion/signals.py @@ -24,5 +24,5 @@ def default_config(sender, key, **kwargs): 'motion_pdf_ballot_papers_number': '8', 'motion_pdf_title': _('Motions'), 'motion_pdf_preamble': '', - 'motion_allow_trivial_change': False, + 'motion_create_new_version': 'ALLWASY_CREATE_NEW_VERSION', }.get(key) diff --git a/openslides/motion/views.py b/openslides/motion/views.py index dcc8eaf8d..d02aac3c3 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -30,7 +30,7 @@ from openslides.projector.projector import Widget, SLIDE from openslides.config.models import config from .models import Motion, MotionSubmitter, MotionSupporter from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin, - MotionTrivialChangesMixin, ConfigForm) + MotionCreateNewVersionMixin, ConfigForm) class MotionListView(ListView): """ @@ -72,6 +72,12 @@ class MotionMixin(object): for attr in ['title', 'text', 'reason']: setattr(self.object, attr, form.cleaned_data[attr]) + try: + if form.cleaned_data['new_version']: + self.object.new_version + except KeyError: + pass + def post_save(self, form): super(MotionMixin, self).post_save(form) # TODO: only delete and save neccessary submitters and supporter @@ -90,8 +96,8 @@ class MotionMixin(object): form_classes.append(MotionSubmitterMixin) if config['motion_min_supporters'] > 0: form_classes.append(MotionSupporterMixin) - if config['motion_allow_trivial_change']: - form_classes.append(MotionTrivialChangesMixin) + if config['motion_create_new_version'] == 'ASK_USER': + form_classes.append(MotionCreateNewVersionMixin) return type('MotionForm', tuple(form_classes), {}) @@ -129,7 +135,7 @@ class Config(FormView): 'motion_pdf_ballot_papers_number': config['motion_pdf_ballot_papers_number'], 'motion_pdf_title': config['motion_pdf_title'], 'motion_pdf_preamble': config['motion_pdf_preamble'], - 'motion_allow_trivial_change': config['motion_allow_trivial_change'], + 'motion_create_new_version': config['motion_create_new_version'], } def form_valid(self, form): @@ -139,7 +145,7 @@ class Config(FormView): config['motion_pdf_ballot_papers_number'] = form.cleaned_data['motion_pdf_ballot_papers_number'] config['motion_pdf_title'] = form.cleaned_data['motion_pdf_title'] config['motion_pdf_preamble'] = form.cleaned_data['motion_pdf_preamble'] - config['motion_allow_trivial_change'] = form.cleaned_data['motion_allow_trivial_change'] + config['motion_create_new_version'] = form.cleaned_data['motion_create_new_version'] messages.success(self.request, _('Motion settings successfully saved.')) return super(Config, self).form_valid(form)