Let the user choose if the motion should have a new version

via config or form
This commit is contained in:
Oskar Hahn 2013-01-26 17:09:13 +01:00
parent 0702d49e2e
commit 87e42cf9f8
4 changed files with 24 additions and 15 deletions

View File

@ -61,9 +61,9 @@ class MotionSupporterMixin(forms.ModelForm):
super(MotionSupporterMixin, self).__init__(*args, **kwargs) super(MotionSupporterMixin, self).__init__(*args, **kwargs)
class MotionTrivialChangesMixin(forms.ModelForm): class MotionCreateNewVersionMixin(forms.ModelForm):
trivial_change = forms.BooleanField( new_version = forms.BooleanField(
required=False, label=_("Trivial change"), required=False, label=_("Create new version"), initial=True,
help_text=_("Trivial changes don't create a new version.")) 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)") label=_("Preamble text for PDF document (all motions)")
) )
motion_allow_trivial_change = forms.BooleanField( motion_create_new_version = forms.ChoiceField(
label=_("Allow trivial changes"), widget=forms.Select(),
help_text=_('Warning: Trivial changes undermine the motions ' label=_("Create new versions"),
'autorisation system.'),
required=False, 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')))
) )

View File

@ -94,8 +94,8 @@ class Motion(SlideMixin, models.Model):
else: else:
new_data = False new_data = False
need_new_version = True # TODO: Do we need a new version (look in config) need_new_version = config['motion_create_new_version'] == 'ALLWASY_CREATE_NEW_VERSION'
if hasattr(self, '_version') or (new_data and need_new_version): if hasattr(self, '_new_version') or (new_data and need_new_version):
version = self.new_version version = self.new_version
del self._new_version del self._new_version
version.motion = self # Test if this line is realy neccessary. version.motion = self # Test if this line is realy neccessary.

View File

@ -24,5 +24,5 @@ def default_config(sender, key, **kwargs):
'motion_pdf_ballot_papers_number': '8', 'motion_pdf_ballot_papers_number': '8',
'motion_pdf_title': _('Motions'), 'motion_pdf_title': _('Motions'),
'motion_pdf_preamble': '', 'motion_pdf_preamble': '',
'motion_allow_trivial_change': False, 'motion_create_new_version': 'ALLWASY_CREATE_NEW_VERSION',
}.get(key) }.get(key)

View File

@ -30,7 +30,7 @@ from openslides.projector.projector import Widget, SLIDE
from openslides.config.models import config from openslides.config.models import config
from .models import Motion, MotionSubmitter, MotionSupporter from .models import Motion, MotionSubmitter, MotionSupporter
from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin, from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin,
MotionTrivialChangesMixin, ConfigForm) MotionCreateNewVersionMixin, ConfigForm)
class MotionListView(ListView): class MotionListView(ListView):
""" """
@ -72,6 +72,12 @@ class MotionMixin(object):
for attr in ['title', 'text', 'reason']: for attr in ['title', 'text', 'reason']:
setattr(self.object, attr, form.cleaned_data[attr]) 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): def post_save(self, form):
super(MotionMixin, self).post_save(form) super(MotionMixin, self).post_save(form)
# TODO: only delete and save neccessary submitters and supporter # TODO: only delete and save neccessary submitters and supporter
@ -90,8 +96,8 @@ class MotionMixin(object):
form_classes.append(MotionSubmitterMixin) form_classes.append(MotionSubmitterMixin)
if config['motion_min_supporters'] > 0: if config['motion_min_supporters'] > 0:
form_classes.append(MotionSupporterMixin) form_classes.append(MotionSupporterMixin)
if config['motion_allow_trivial_change']: if config['motion_create_new_version'] == 'ASK_USER':
form_classes.append(MotionTrivialChangesMixin) form_classes.append(MotionCreateNewVersionMixin)
return type('MotionForm', tuple(form_classes), {}) 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_ballot_papers_number': config['motion_pdf_ballot_papers_number'],
'motion_pdf_title': config['motion_pdf_title'], 'motion_pdf_title': config['motion_pdf_title'],
'motion_pdf_preamble': config['motion_pdf_preamble'], '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): 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_ballot_papers_number'] = form.cleaned_data['motion_pdf_ballot_papers_number']
config['motion_pdf_title'] = form.cleaned_data['motion_pdf_title'] config['motion_pdf_title'] = form.cleaned_data['motion_pdf_title']
config['motion_pdf_preamble'] = form.cleaned_data['motion_pdf_preamble'] 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.')) messages.success(self.request, _('Motion settings successfully saved.'))
return super(Config, self).form_valid(form) return super(Config, self).form_valid(form)