Let the user choose if the motion should have a new version
via config or form
This commit is contained in:
parent
0702d49e2e
commit
87e42cf9f8
@ -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')))
|
||||
)
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user