From 039446a7ca4d8b31b2f3a1857e31a9f7b6089a54 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 30 Jun 2012 11:50:46 +0200 Subject: [PATCH] #239 don't show supporters in application edit form, if there are not needed --- openslides/application/forms.py | 16 ++++++++++++---- openslides/application/views.py | 11 ++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/openslides/application/forms.py b/openslides/application/forms.py index a7b28d086..93ee3e9ac 100644 --- a/openslides/application/forms.py +++ b/openslides/application/forms.py @@ -48,13 +48,21 @@ class ApplicationFormTrivialChanges(ApplicationForm): class ApplicationManagerForm(ModelForm, CssClassMixin): - users = User.objects.all().exclude(profile=None).order_by("first_name") - submitter = UserModelChoiceField(queryset=users, label=_("Submitter")) - supporter = UserModelMultipleChoiceField(queryset=users, required=False, label=_("Supporters")) + submitter = UserModelChoiceField( + queryset=User.objects.all().exclude(profile=None).order_by("first_name"), + label=_("Submitter"), + ) class Meta: model = Application - exclude = ('number', 'status', 'permitted', 'log') + exclude = ('number', 'status', 'permitted', 'log', 'supporter') + + +class ApplicationManagerFormSupporter(ApplicationManagerForm): + supporter = UserModelMultipleChoiceField( + queryset=User.objects.all().exclude(profile=None).order_by("first_name"), + required=False, label=_("Supporters"), + ) class ApplicationImportForm(Form, CssClassMixin): diff --git a/openslides/application/views.py b/openslides/application/views.py index 56c5f70fe..fca8881ca 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -57,6 +57,7 @@ from application.forms import ( ApplicationForm, ApplicationFormTrivialChanges, ApplicationManagerForm, + ApplicationManagerFormSupporter, ApplicationImportForm, ConfigForm, ) @@ -197,12 +198,16 @@ def edit(request, application_id=None): if config['application_allow_trivial_change'] and application_id \ else ApplicationForm + managerformclass = ApplicationManagerFormSupporter \ + if config['application_min_supporters'] \ + else ApplicationManagerForm + if request.method == 'POST': dataform = formclass(request.POST, prefix="data") valid = dataform.is_valid() if is_manager: - managerform = ApplicationManagerForm(request.POST, + managerform = managerformclass(request.POST, instance=application, prefix="manager") valid = valid and managerform.is_valid() @@ -263,7 +268,7 @@ def edit(request, application_id=None): if application_id is None: initial = {'text': config['application_preamble']} else: - if application.status == "pub" and application.supporter.count() > 0: + if application.status == "pub" and application.supporter.exists(): if request.user.has_perm('application.can_manage_application'): messages.warning(request, _("Attention: Do you really want to edit this application? The supporters will not be removed automatically because you can manage applications. Please check if the supports are valid after your changing!")) else: @@ -278,7 +283,7 @@ def edit(request, application_id=None): initial = {'submitter': str(request.user.id)} else: initial = {} - managerform = ApplicationManagerForm(initial=initial, \ + managerform = managerformclass(initial=initial, \ instance=application, \ prefix="manager") else: