|
1 | 1 | from django import newforms as forms |
2 | 2 | from models import NonWgMailingList, ImportedMailingList |
3 | 3 | from ietf.idtracker.models import PersonOrOrgInfo, IETFWG, Acronym |
| 4 | +import re |
4 | 5 |
|
5 | 6 | class NonWgStep1(forms.Form): |
6 | 7 | add_edit = forms.ChoiceField(choices=( |
@@ -42,28 +43,27 @@ class ListReqStep1(forms.Form): |
42 | 43 | ('newnon', 'Create new non-WG email list at selected domain above'), |
43 | 44 | ('movenon', 'Move existing non-WG email list to selected domain above'), |
44 | 45 | ('closenon', 'Close existing non-WG email list at selected domain above'), |
45 | | - ), widget=forms.RadioSelect) |
| 46 | + ), widget=forms.RadioSelect()) |
46 | 47 | #group = forms.ChoiceField(required=False) |
47 | 48 | group = forms.ModelChoiceField(queryset=IETFWG.objects.all().select_related().order_by('acronym.acronym'), required=False, empty_label="-- Select Working Group") |
48 | | - domain_name = forms.ChoiceField(choices=DOMAIN_CHOICES, required=False) |
| 49 | + domain_name = forms.ChoiceField(choices=DOMAIN_CHOICES, required=False, widget = forms.Select(attrs={'onChange': 'set_domain(this)'})) |
49 | 50 | list_to_close = forms.ModelChoiceField(queryset=ImportedMailingList.objects.all(), required=False, empty_label="-- Select List To Close") |
50 | 51 | def mail_type_fields(self): |
51 | 52 | field = self['mail_type'] |
52 | | - return field.as_widget(field.field.widget) |
| 53 | + # RadioSelect() doesn't pass its attributes through to the <input> |
| 54 | + # elements, so in order to get the javascript onClick we add it here. |
| 55 | + return [re.sub(r'input ','input onClick="activate_widgets()" ',str(i)) for i in field.as_widget(field.field.widget)] |
53 | 56 | def __init__(self, *args, **kwargs): |
54 | | - dname = 'ietf.org' |
55 | | - if args and args[0]: |
56 | | - dn = 'domain_name' |
57 | | - if kwargs.has_key('prefix'): |
58 | | - dn = kwargs['prefix'] + '-' + dn |
59 | | - dname = args[0][dn] |
60 | | - dname = kwargs.get('dname', dname) |
| 57 | + initial = kwargs.get('initial', None) |
| 58 | + # could pass initial = None, so can't use a trick on the |
| 59 | + # above get. |
| 60 | + if initial: |
| 61 | + dname = initial.get('domain_name', 'ietf.org') |
| 62 | + else: |
| 63 | + dname = 'ietf.org' |
61 | 64 | super(ListReqStep1, self).__init__(*args, **kwargs) |
62 | | - #self.fields['group'].choices = [('', '-- Select Working Group')] + IETFWG.choices() |
63 | | - #self.fields['list_to_close'].choices = [('', '-- Select List To Close')] + ImportedMailingList.choices(dname) |
64 | | - #XXX This doesn't work yet. Maybe switch back to choices. |
65 | 65 | self.fields['list_to_close'].queryset = ImportedMailingList.choices(dname) |
66 | | - print "dname %s list_to_close values: %s" % (dname, self.fields['list_to_close'].queryset) |
| 66 | + self.fields['list_to_close'].widget.choices = self.fields['list_to_close'].choices |
67 | 67 | self.fields['domain_name'].initial = dname |
68 | 68 | def clean_group(self): |
69 | 69 | group = self.clean_data['group'] |
@@ -181,7 +181,7 @@ def decompress(self, value): |
181 | 181 | # check the checkbox, but for now let's try this. |
182 | 182 | return ['', '', value] |
183 | 183 | def __init__(self, attrs=None): |
184 | | - widgets = (forms.CheckboxInput(), forms.TextInput(attrs={'size': 55, 'disabled': True}), forms.Textarea(attrs=attrs)) |
| 184 | + widgets = (forms.CheckboxInput(attrs={'onClick': 'checkthis()'}), forms.TextInput(attrs={'size': 55, 'disabled': True}), forms.Textarea(attrs=attrs)) |
185 | 185 | super(AdminRequestor, self).__init__(widgets, attrs) |
186 | 186 | def format_output(self, rendered_widgets): |
187 | 187 | return u'<br/>\n'.join(["<label>%s Same as requestor</label>" % rendered_widgets[0]] + rendered_widgets[1:]) |
|
0 commit comments