#239 don't show supporters in application edit form, if there are not needed

This commit is contained in:
Oskar Hahn 2012-06-30 11:50:46 +02:00
parent 018d53b3df
commit 039446a7ca
2 changed files with 20 additions and 7 deletions

View File

@ -48,13 +48,21 @@ class ApplicationFormTrivialChanges(ApplicationForm):
class ApplicationManagerForm(ModelForm, CssClassMixin): class ApplicationManagerForm(ModelForm, CssClassMixin):
users = User.objects.all().exclude(profile=None).order_by("first_name") submitter = UserModelChoiceField(
submitter = UserModelChoiceField(queryset=users, label=_("Submitter")) queryset=User.objects.all().exclude(profile=None).order_by("first_name"),
supporter = UserModelMultipleChoiceField(queryset=users, required=False, label=_("Supporters")) label=_("Submitter"),
)
class Meta: class Meta:
model = Application 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): class ApplicationImportForm(Form, CssClassMixin):

View File

@ -57,6 +57,7 @@ from application.forms import (
ApplicationForm, ApplicationForm,
ApplicationFormTrivialChanges, ApplicationFormTrivialChanges,
ApplicationManagerForm, ApplicationManagerForm,
ApplicationManagerFormSupporter,
ApplicationImportForm, ApplicationImportForm,
ConfigForm, ConfigForm,
) )
@ -197,12 +198,16 @@ def edit(request, application_id=None):
if config['application_allow_trivial_change'] and application_id \ if config['application_allow_trivial_change'] and application_id \
else ApplicationForm else ApplicationForm
managerformclass = ApplicationManagerFormSupporter \
if config['application_min_supporters'] \
else ApplicationManagerForm
if request.method == 'POST': if request.method == 'POST':
dataform = formclass(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 = managerformclass(request.POST,
instance=application, instance=application,
prefix="manager") prefix="manager")
valid = valid and managerform.is_valid() valid = valid and managerform.is_valid()
@ -263,7 +268,7 @@ def edit(request, application_id=None):
if application_id is None: if application_id is None:
initial = {'text': config['application_preamble']} initial = {'text': config['application_preamble']}
else: 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'): if request.user.has_perm('application.can_manage_application'):
messages.warning(request, _("Attention: Do you really want to edit this application? The supporters will <b>not</b> be removed automatically because you can manage applications. Please check if the supports are valid after your changing!")) messages.warning(request, _("Attention: Do you really want to edit this application? The supporters will <b>not</b> be removed automatically because you can manage applications. Please check if the supports are valid after your changing!"))
else: else:
@ -278,7 +283,7 @@ def edit(request, application_id=None):
initial = {'submitter': str(request.user.id)} initial = {'submitter': str(request.user.id)}
else: else:
initial = {} initial = {}
managerform = ApplicationManagerForm(initial=initial, \ managerform = managerformclass(initial=initial, \
instance=application, \ instance=application, \
prefix="manager") prefix="manager")
else: else: