From 018d53b3dfa35c291587cd6afd8f97c7e9a106e4 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 30 Jun 2012 11:31:35 +0200 Subject: [PATCH] #236, #244 make trivial_changes optional, and only in the edit form --- openslides/application/forms.py | 12 +++++++++++- openslides/application/models.py | 1 + openslides/application/views.py | 19 ++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/openslides/application/forms.py b/openslides/application/forms.py index aa10cf814..a7b28d086 100644 --- a/openslides/application/forms.py +++ b/openslides/application/forms.py @@ -40,7 +40,11 @@ class ApplicationForm(Form, CssClassMixin): title = CharField(widget=TextInput(), label=_("Title")) text = CharField(widget=Textarea(), label=_("Text")) reason = CharField(widget=Textarea(), required=False, label=_("Reason")) - trivial_change = BooleanField(required=False, label=_("Trivial change"), help_text=_("Trivial changes don't create a new version.")) + + +class ApplicationFormTrivialChanges(ApplicationForm): + trivial_change = BooleanField(required=False, label=_("Trivial change"), + help_text=_("Trivial changes don't create a new version.")) class ApplicationManagerForm(ModelForm, CssClassMixin): @@ -97,3 +101,9 @@ class ConfigForm(Form, CssClassMixin): required=False, label=_("Preamble text for PDF document (all applications)") ) + + application_allow_trivial_change = BooleanField( + label=_("Allow trivial changes"), + help_text=_('Warning: Trivial changes undermine the application permission system.'), + required=False, + ) diff --git a/openslides/application/models.py b/openslides/application/models.py index e1f9c6768..69d3fd01e 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -579,4 +579,5 @@ def default_config(sender, key, **kwargs): 'application_pdf_ballot_papers_number': '8', 'application_pdf_title': _('Applications'), 'application_pdf_preamble': '', + 'application_allow_trivial_change': False, }.get(key) diff --git a/openslides/application/views.py b/openslides/application/views.py index 8f4c060fd..56c5f70fe 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -55,6 +55,7 @@ from agenda.models import Item from application.models import Application, AVersion, ApplicationPoll from application.forms import ( ApplicationForm, + ApplicationFormTrivialChanges, ApplicationManagerForm, ApplicationImportForm, ConfigForm, @@ -192,13 +193,17 @@ def edit(request, application_id=None): application = None actions = None + formclass = ApplicationFormTrivialChanges \ + if config['application_allow_trivial_change'] and application_id \ + else ApplicationForm + if request.method == 'POST': - dataform = ApplicationForm(request.POST, prefix="data") + dataform = formclass(request.POST, prefix="data") valid = dataform.is_valid() if is_manager: - managerform = ApplicationManagerForm(request.POST, \ - instance=application, \ + managerform = ApplicationManagerForm(request.POST, + instance=application, prefix="manager") valid = valid and managerform.is_valid() else: @@ -217,7 +222,9 @@ def edit(request, application_id=None): application.title = dataform.cleaned_data['title'] application.text = dataform.cleaned_data['text'] application.reason = dataform.cleaned_data['reason'] - application.save(request.user, trivial_change=dataform.cleaned_data['trivial_change']) + trivial_change = config['application_allow_trivial_change'] \ + and dataform.cleaned_data['trivial_change'] + application.save(request.user, trivial_change=trivial_change) if is_manager: # log added supporters supporters_added = [] @@ -265,7 +272,7 @@ def edit(request, application_id=None): 'text': application.text, 'reason': application.reason} - dataform = ApplicationForm(initial=initial, prefix="data") + dataform = formclass(initial=initial, prefix="data") if is_manager: if application_id is None: initial = {'submitter': str(request.user.id)} @@ -884,6 +891,7 @@ class Config(FormView): 'application_pdf_ballot_papers_number': config['application_pdf_ballot_papers_number'], 'application_pdf_title': config['application_pdf_title'], 'application_pdf_preamble': config['application_pdf_preamble'], + 'application_allow_trivial_change': config['application_allow_trivial_change'], } def form_valid(self, form): @@ -893,6 +901,7 @@ class Config(FormView): config['application_pdf_ballot_papers_number'] = form.cleaned_data['application_pdf_ballot_papers_number'] config['application_pdf_title'] = form.cleaned_data['application_pdf_title'] config['application_pdf_preamble'] = form.cleaned_data['application_pdf_preamble'] + config['application_allow_trivial_change'] = form.cleaned_data['application_allow_trivial_change'] messages.success(self.request, _('Application settings successfully saved.')) return super(Config, self).form_valid(form)