1313from datetime import datetime
1414
1515def get_approvers_from_area (area_id ) :
16- if not area_id :
17- return [ad .person_id for ad in Role .objects .filter (role_name__in = ("IETF" , "IAB" , ))]
18- else :
19- return [ad .person_id for ad in Area .objects .get (area_acronym = area_id ).areadirector_set .all ()]
16+ if not area_id :
17+ return [ad .person_id for ad in Role .objects .filter (role_name__in = ("IETF" , "IAB" , ))]
18+ else :
19+ return [ad .person_id for ad in Area .objects .get (area_acronym = area_id ).areadirector_set .all ()]
2020
2121def formchoice (form , field ):
2222 if not (form .is_valid ()):
@@ -40,6 +40,7 @@ def formchoice(form, field):
4040 'ds_name' : None ,
4141 'ds_email' : None ,
4242 'msg_to_ad' : None ,
43+ 'area' : forms .ModelChoiceField (Area .objects .filter (status = 1 ), required = False , empty_label = 'none' ),
4344 #'admin': MultiEmailField(label='List Administrator(s)', widget=forms.Textarea(attrs={'rows': 3, 'cols': 50})),
4445}
4546
@@ -57,10 +58,7 @@ def formchoice(form, field):
5758 'subscribe_other' : forms .Textarea (attrs = {'rows' : 3 , 'cols' : 50 }),
5859}
5960
60- nonwg_querysets = {
61- #'area': Area.objects.filter(status=1)
62- }
63-
61+ nonwg_callback = form_decorator (fields = nonwg_fields , widgets = nonwg_widgets , attrs = nonwg_attrs )
6462
6563def gen_approval (approvers , parent ):
6664 class BoundApproval (parent ):
@@ -105,16 +103,15 @@ def process_step(self, request, form, step):
105103 if step == 0 :
106104 self .clean_forms = [ form ]
107105 if form .clean_data ['add_edit' ] == 'add' :
108- nonwg_fields ["area" ] = forms .ModelChoiceField (Area .objects .filter (status = 1 ), required = False , empty_label = 'none' )
109- nonwg_callback = form_decorator (fields = nonwg_fields , widgets = nonwg_widgets , attrs = nonwg_attrs , querysets = nonwg_querysets )
110-
111106 self .form_list .append (forms .form_for_model (NonWgMailingList , formfield_callback = nonwg_callback ))
112107 elif form .clean_data ['add_edit' ] == 'edit' :
113108 list = NonWgMailingList .objects .get (pk = form .clean_data ['list_id' ])
114- 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 )
115- nonwg_callback = form_decorator (fields = nonwg_fields , widgets = nonwg_widgets , attrs = nonwg_attrs , querysets = nonwg_querysets )
116-
117- self .form_list .append (forms .form_for_instance (list , formfield_callback = nonwg_callback ))
109+ f = forms .form_for_instance (list , formfield_callback = nonwg_callback )
110+ # form_decorator's method of copying the initial data
111+ # from form_for_instance() to the ModelChoiceField doesn't
112+ # work, so we set it explicitly here.
113+ f .base_fields ['area' ].initial = list .area_id
114+ self .form_list .append (f )
118115 elif form .clean_data ['add_edit' ] == 'delete' :
119116 list = NonWgMailingList .objects .get (pk = form .clean_data ['list_id_delete' ])
120117 self .form_list .append (gen_approval (get_approvers_from_area (list .area is None or list .area_id ), DeletionPickApprover ))
@@ -135,9 +132,6 @@ def done(self, request, form_list):
135132 if add_edit == 'add' or add_edit == 'edit' :
136133 template = 'mailinglists/nwg_addedit_email.txt'
137134 approver = self .clean_forms [2 ].clean_data ['approver' ]
138- if not self .clean_forms [1 ].clean_data ["area" ] :
139- self .clean_forms [1 ].clean_data ["area" ] = None
140-
141135 list = NonWgMailingList (** self .clean_forms [1 ].clean_data )
142136 list .__dict__ .update (self .clean_forms [2 ].clean_data )
143137 list .id = None # create a new row no matter what
0 commit comments