Skip to content

Commit

Permalink
Resolve ticket #205
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Michael Lee committed Oct 30, 2007
1 parent 1163829 commit a7b3240
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions ietf/mailinglists/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
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()):
Expand All @@ -40,6 +40,7 @@ def formchoice(form, field):
'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})),
}

Expand All @@ -57,10 +58,7 @@ def formchoice(form, field):
'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):
Expand Down Expand Up @@ -105,16 +103,15 @@ def process_step(self, request, form, step):
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))
Expand All @@ -135,9 +132,6 @@ def done(self, request, form_list):
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
Expand Down

0 comments on commit a7b3240

Please sign in to comment.