|
| 1 | +from django import newforms as forms |
| 2 | +from models import NonWgMailingList, ImportedMailingList |
| 3 | +from ietf.idtracker.models import PersonOrOrgInfo, GroupIETF |
| 4 | + |
| 5 | +class NonWgStep1(forms.Form): |
| 6 | + add_edit = forms.ChoiceField(choices=( |
| 7 | + ('add', 'Add a new entry'), |
| 8 | + ('edit', 'Modify an existing entry'), |
| 9 | + ('delete', 'Delete an existing entry'), |
| 10 | + ), widget=forms.RadioSelect) |
| 11 | + list_id = forms.ChoiceField(required=False) |
| 12 | + list_id_delete = forms.ChoiceField(required=False) |
| 13 | + def add_edit_fields(self): |
| 14 | + field = self['add_edit'] |
| 15 | + return field.as_widget(field.field.widget) |
| 16 | + def __init__(self, *args, **kwargs): |
| 17 | + super(NonWgStep1, self).__init__(*args, **kwargs) |
| 18 | + choices=[('', '-- Select an item from the list below')] + NonWgMailingList.choices() |
| 19 | + self.fields['list_id'].choices = choices |
| 20 | + self.fields['list_id_delete'].choices = choices |
| 21 | + def clean_list_id(self): |
| 22 | + if self.clean_data.get('add_edit', None) == 'edit': |
| 23 | + if not self.clean_data.get('list_id'): |
| 24 | + raise forms.ValidationError, 'Please pick a mailing list to modify' |
| 25 | + return self.clean_data['list_id'] |
| 26 | + def clean_list_id_delete(self): |
| 27 | + if self.clean_data.get('add_edit', None) == 'delete': |
| 28 | + if not self.clean_data.get('list_id_delete'): |
| 29 | + raise forms.ValidationError, 'Please pick a mailing list to delete' |
| 30 | + return self.clean_data['list_id_delete'] |
| 31 | + |
| 32 | +class ListReqStep1(forms.Form): |
| 33 | + DOMAIN_CHOICES = ( |
| 34 | + ('ietf.org', 'ietf.org'), |
| 35 | + ('iab.org', 'iab.org'), |
| 36 | + ('irtf.org', 'irtf.org'), |
| 37 | + ) |
| 38 | + mail_type = forms.ChoiceField(choices=( |
| 39 | + ('newwg', 'Create new WG email list at ietf.org'), |
| 40 | + ('movewg', 'Move existing WG email list to ietf.org'), |
| 41 | + ('closewg', 'Close existing WG email list at ietf.org'), |
| 42 | + ('newnon', 'Create new non-WG email list at selected domain above'), |
| 43 | + ('movenon', 'Move existing non-WG email list to selected domain above'), |
| 44 | + ('closenon', 'Close existing non-WG email list at selected domain above'), |
| 45 | + ), widget=forms.RadioSelect) |
| 46 | + group = forms.ChoiceField(required=False) |
| 47 | + domain_name = forms.ChoiceField(choices=DOMAIN_CHOICES, required=False) |
| 48 | + list_to_close = forms.ChoiceField(required=False) |
| 49 | + def mail_type_fields(self): |
| 50 | + field = self['mail_type'] |
| 51 | + return field.as_widget(field.field.widget) |
| 52 | + def __init__(self, *args, **kwargs): |
| 53 | + dname = kwargs.get('dname', 'ietf.org') |
| 54 | + super(ListReqStep1, self).__init__(*args, **kwargs) |
| 55 | + self.fields['group'].choices = [('', '-- Select Working Group')] + GroupIETF.choices() |
| 56 | + self.fields['list_to_close'].choices = [('', '-- Select List To Close')] + ImportedMailingList.choices(dname) |
| 57 | + self.fields['domain_name'].initial = dname |
| 58 | + def clean_group(self): |
| 59 | + if self.clean_data.get('mail_type', '').endswith('wg'): |
| 60 | + if not self.clean_data.get('group'): |
| 61 | + raise forms.ValidationError, 'Please pick a working group' |
| 62 | + return self.clean_data['group'] |
| 63 | + def clean_list_to_close(self): |
| 64 | + if self.clean_data.get('mail_type', '') == 'closenon': |
| 65 | + if not self.clean_data.get('list_to_close'): |
| 66 | + raise forms.ValidationError, 'Please pick a list to close' |
| 67 | + return self.clean_data['list_to_close'] |
| 68 | + |
| 69 | +# multiwidget for separate scheme and rest for urls |
| 70 | +# todo: can the clean return the "smart" value? |
| 71 | +class UrlMultiWidget(forms.MultiWidget): |
| 72 | + def decompress(self, value): |
| 73 | + if value: |
| 74 | + if '//' in value: |
| 75 | + (scheme, rest) = value.split('//', 1) |
| 76 | + scheme += '//' |
| 77 | + else: |
| 78 | + scheme = 'http://' |
| 79 | + rest = value |
| 80 | + return [scheme, rest] |
| 81 | + else: |
| 82 | + return ['', ''] |
| 83 | + |
| 84 | + def __init__(self, choices=(('http://', 'http://'), ('https://', 'https://')), attrs=None): |
| 85 | + widgets = (forms.RadioSelect(choices=choices, attrs=attrs), forms.TextInput(attrs=attrs)) |
| 86 | + super(UrlMultiWidget, self).__init__(widgets, attrs) |
| 87 | + |
| 88 | + def format_output(self, rendered_widgets): |
| 89 | + return u'%s\n%s\n<br/>' % ( u'<br/>\n'.join(["%s" % w for w in rendered_widgets[0]]), rendered_widgets[1] ) |
| 90 | + |
| 91 | + |
| 92 | +class PickApprover(forms.Form): |
| 93 | + """ |
| 94 | + When instantiating, supply a list of person tags in approvers= |
| 95 | + """ |
| 96 | + approver = forms.ChoiceField(choices=( |
| 97 | + ('', '-- Pick an approver from the list below'), |
| 98 | + )) |
| 99 | + def __init__(self, approvers, *args, **kwargs): |
| 100 | + super(PickApprover, self).__init__(*args, **kwargs) |
| 101 | + self.fields['approver'].choices = [('', '-- Pick an approver from the list below')] + [(person.person_or_org_tag, str(person)) for person in PersonOrOrgInfo.objects.filter(pk__in=approvers)] |
| 102 | + |
| 103 | +class DeletionPickApprover(PickApprover): |
| 104 | + ds_name = forms.CharField(label = 'Enter your name', widget = forms.TextInput(attrs = {'size': 45})) |
| 105 | + ds_email = forms.EmailField(label = 'Enter your email', widget = forms.TextInput(attrs = {'size': 45})) |
| 106 | + msg_to_ad = forms.CharField(label = 'Message to the Area Director', widget = forms.Textarea(attrs = {'rows': 5, 'cols': 50})) |
0 commit comments