Skip to content

Commit 6396c8e

Browse files
committed
Use (some) new class functions to generate choices
Defer choice generation from database until object instantiation. - Legacy-Id: 124
1 parent 561c97b commit 6396c8e

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

ietf/idindex/forms.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from django import newforms as forms
2-
from itertools import chain
32
from ietf.idtracker.models import IDState, IDStatus, GroupIETF
43
from ietf.idindex.models import orgs
54

65
class IDIndexSearchForm(forms.Form):
76
filename = forms.CharField(max_length=100, label='Filename (Full or Partial):', widget=forms.TextInput(attrs={'size': 30}))
8-
id_tracker_state_id = forms.ChoiceField(choices=chain((('', 'All/Any'),),
9-
[(state.document_state_id, state.state) for state in IDState.objects.all()]), label='I-D Tracker State:')
10-
wg_id = forms.ChoiceField(choices=chain((('', 'All/Any'),),
11-
[(wg.group_acronym_id, wg.group_acronym.acronym) for wg in GroupIETF.objects.all().select_related().order_by('acronym.acronym')]), label='Working Group:')
12-
other_group = forms.ChoiceField(choices=chain((('', 'All/Any'),),
13-
[(org['key'], org['name']) for org in orgs]), label='Other Group:')
14-
status_id = forms.ChoiceField(choices=chain((('', 'All/Any'),),
15-
[(status.status_id, status.status) for status in IDStatus.objects.all()]), label='I-D Status:')
7+
id_tracker_state_id = forms.ChoiceField(label='I-D Tracker State:')
8+
wg_id = forms.ChoiceField(label='Working Group:')
9+
other_group = forms.ChoiceField(choices=[('', 'All/Any')] + [(org['key'], org['name']) for org in orgs], label='Other Group:')
10+
status_id = forms.ChoiceField(label='I-D Status:')
1611
last_name = forms.CharField(max_length=50)
1712
first_name = forms.CharField(max_length=50)
13+
def __init__(self, *args, **kwargs):
14+
super(IDIndexSearchForm, self).__init__(*args, **kwargs)
15+
self.fields['id_tracker_state_id'].choices = [('', 'All/Any')] + IDState.choices()
16+
self.fields['wg_id'].choices = [('', 'All/Any')] + GroupIETF.choices()
17+
self.fields['status_id'].choices = [('', 'All/Any')] + [(status.status_id, status.status) for status in IDStatus.objects.all()]

0 commit comments

Comments
 (0)