Resolve ticket #205
* Relocate the form_decorator definition for area drop down to make the form_for_model case simpler * Remove lines that are not used to handle 'None' area. - Legacy-Id: 961
This commit is contained in:
parent
1163829ed2
commit
a7b3240bb8
|
@ -13,10 +13,10 @@ from ietf.utils.mail import send_mail_subj
|
|||
from datetime import datetime
|
||||
|
||||
def get_approvers_from_area (area_id) :
|
||||
if not area_id :
|
||||
return [ad.person_id for ad in Role.objects.filter(role_name__in=("IETF", "IAB", ))]
|
||||
else :
|
||||
return [ad.person_id for ad in Area.objects.get(area_acronym=area_id).areadirector_set.all()]
|
||||
if not area_id :
|
||||
return [ad.person_id for ad in Role.objects.filter(role_name__in=("IETF", "IAB", ))]
|
||||
else :
|
||||
return [ad.person_id for ad in Area.objects.get(area_acronym=area_id).areadirector_set.all()]
|
||||
|
||||
def formchoice(form, field):
|
||||
if not(form.is_valid()):
|
||||
|
@ -40,6 +40,7 @@ nonwg_fields = {
|
|||
'ds_name': None,
|
||||
'ds_email': None,
|
||||
'msg_to_ad': None,
|
||||
'area': forms.ModelChoiceField(Area.objects.filter(status=1), required=False, empty_label='none'),
|
||||
#'admin': MultiEmailField(label='List Administrator(s)', widget=forms.Textarea(attrs={'rows': 3, 'cols': 50})),
|
||||
}
|
||||
|
||||
|
@ -57,10 +58,7 @@ nonwg_widgets = {
|
|||
'subscribe_other': forms.Textarea(attrs = {'rows': 3, 'cols': 50}),
|
||||
}
|
||||
|
||||
nonwg_querysets = {
|
||||
#'area': Area.objects.filter(status=1)
|
||||
}
|
||||
|
||||
nonwg_callback = form_decorator(fields=nonwg_fields, widgets=nonwg_widgets, attrs=nonwg_attrs)
|
||||
|
||||
def gen_approval(approvers, parent):
|
||||
class BoundApproval(parent):
|
||||
|
@ -105,16 +103,15 @@ class NonWgWizard(wizard.Wizard):
|
|||
if step == 0:
|
||||
self.clean_forms = [ form ]
|
||||
if form.clean_data['add_edit'] == 'add':
|
||||
nonwg_fields["area"] = forms.ModelChoiceField(Area.objects.filter(status=1), required=False, empty_label='none')
|
||||
nonwg_callback = form_decorator(fields=nonwg_fields, widgets=nonwg_widgets, attrs=nonwg_attrs, querysets=nonwg_querysets)
|
||||
|
||||
self.form_list.append(forms.form_for_model(NonWgMailingList, formfield_callback=nonwg_callback))
|
||||
elif form.clean_data['add_edit'] == 'edit':
|
||||
list = NonWgMailingList.objects.get(pk=form.clean_data['list_id'])
|
||||
nonwg_fields["area"] = forms.ModelChoiceField(Area.objects.filter(status=1), required=False, empty_label='none',initial=list.area_id is None or list.area_id)
|
||||
nonwg_callback = form_decorator(fields=nonwg_fields, widgets=nonwg_widgets, attrs=nonwg_attrs, querysets=nonwg_querysets)
|
||||
|
||||
self.form_list.append(forms.form_for_instance(list, formfield_callback=nonwg_callback))
|
||||
f = forms.form_for_instance(list, formfield_callback=nonwg_callback)
|
||||
# form_decorator's method of copying the initial data
|
||||
# from form_for_instance() to the ModelChoiceField doesn't
|
||||
# work, so we set it explicitly here.
|
||||
f.base_fields['area'].initial = list.area_id
|
||||
self.form_list.append(f)
|
||||
elif form.clean_data['add_edit'] == 'delete':
|
||||
list = NonWgMailingList.objects.get(pk=form.clean_data['list_id_delete'])
|
||||
self.form_list.append(gen_approval(get_approvers_from_area(list.area is None or list.area_id), DeletionPickApprover))
|
||||
|
@ -135,9 +132,6 @@ class NonWgWizard(wizard.Wizard):
|
|||
if add_edit == 'add' or add_edit == 'edit':
|
||||
template = 'mailinglists/nwg_addedit_email.txt'
|
||||
approver = self.clean_forms[2].clean_data['approver']
|
||||
if not self.clean_forms[1].clean_data["area"] :
|
||||
self.clean_forms[1].clean_data["area"] = None
|
||||
|
||||
list = NonWgMailingList(**self.clean_forms[1].clean_data)
|
||||
list.__dict__.update(self.clean_forms[2].clean_data)
|
||||
list.id = None # create a new row no matter what
|
||||
|
|
Loading…
Reference in a new issue