#236, #244 make trivial_changes optional, and only in the edit form

This commit is contained in:
Oskar Hahn 2012-06-30 11:31:35 +02:00
parent b9f783e9f1
commit 018d53b3df
3 changed files with 26 additions and 6 deletions

View File

@ -40,7 +40,11 @@ class ApplicationForm(Form, CssClassMixin):
title = CharField(widget=TextInput(), label=_("Title")) title = CharField(widget=TextInput(), label=_("Title"))
text = CharField(widget=Textarea(), label=_("Text")) text = CharField(widget=Textarea(), label=_("Text"))
reason = CharField(widget=Textarea(), required=False, label=_("Reason")) 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): class ApplicationManagerForm(ModelForm, CssClassMixin):
@ -97,3 +101,9 @@ class ConfigForm(Form, CssClassMixin):
required=False, required=False,
label=_("Preamble text for PDF document (all applications)") 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,
)

View File

@ -579,4 +579,5 @@ def default_config(sender, key, **kwargs):
'application_pdf_ballot_papers_number': '8', 'application_pdf_ballot_papers_number': '8',
'application_pdf_title': _('Applications'), 'application_pdf_title': _('Applications'),
'application_pdf_preamble': '', 'application_pdf_preamble': '',
'application_allow_trivial_change': False,
}.get(key) }.get(key)

View File

@ -55,6 +55,7 @@ from agenda.models import Item
from application.models import Application, AVersion, ApplicationPoll from application.models import Application, AVersion, ApplicationPoll
from application.forms import ( from application.forms import (
ApplicationForm, ApplicationForm,
ApplicationFormTrivialChanges,
ApplicationManagerForm, ApplicationManagerForm,
ApplicationImportForm, ApplicationImportForm,
ConfigForm, ConfigForm,
@ -192,13 +193,17 @@ def edit(request, application_id=None):
application = None application = None
actions = None actions = None
formclass = ApplicationFormTrivialChanges \
if config['application_allow_trivial_change'] and application_id \
else ApplicationForm
if request.method == 'POST': if request.method == 'POST':
dataform = ApplicationForm(request.POST, prefix="data") dataform = formclass(request.POST, prefix="data")
valid = dataform.is_valid() valid = dataform.is_valid()
if is_manager: if is_manager:
managerform = ApplicationManagerForm(request.POST, \ managerform = ApplicationManagerForm(request.POST,
instance=application, \ instance=application,
prefix="manager") prefix="manager")
valid = valid and managerform.is_valid() valid = valid and managerform.is_valid()
else: else:
@ -217,7 +222,9 @@ def edit(request, application_id=None):
application.title = dataform.cleaned_data['title'] application.title = dataform.cleaned_data['title']
application.text = dataform.cleaned_data['text'] application.text = dataform.cleaned_data['text']
application.reason = dataform.cleaned_data['reason'] 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: if is_manager:
# log added supporters # log added supporters
supporters_added = [] supporters_added = []
@ -265,7 +272,7 @@ def edit(request, application_id=None):
'text': application.text, 'text': application.text,
'reason': application.reason} 'reason': application.reason}
dataform = ApplicationForm(initial=initial, prefix="data") dataform = formclass(initial=initial, prefix="data")
if is_manager: if is_manager:
if application_id is None: if application_id is None:
initial = {'submitter': str(request.user.id)} 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_ballot_papers_number': config['application_pdf_ballot_papers_number'],
'application_pdf_title': config['application_pdf_title'], 'application_pdf_title': config['application_pdf_title'],
'application_pdf_preamble': config['application_pdf_preamble'], 'application_pdf_preamble': config['application_pdf_preamble'],
'application_allow_trivial_change': config['application_allow_trivial_change'],
} }
def form_valid(self, form): 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_ballot_papers_number'] = form.cleaned_data['application_pdf_ballot_papers_number']
config['application_pdf_title'] = form.cleaned_data['application_pdf_title'] config['application_pdf_title'] = form.cleaned_data['application_pdf_title']
config['application_pdf_preamble'] = form.cleaned_data['application_pdf_preamble'] 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.')) messages.success(self.request, _('Application settings successfully saved.'))
return super(Config, self).form_valid(form) return super(Config, self).form_valid(form)