improved filter form
This commit is contained in:
@@ -752,7 +752,66 @@ class RaceResultFilterForm(forms.Form):
|
||||
label='Weight Category',
|
||||
initial=['hwt','lwt'],
|
||||
widget=forms.CheckboxSelectMultiple())
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'records' in kwargs:
|
||||
records = kwargs.pop('records',None)
|
||||
|
||||
super(RaceResultFilterForm,self).__init__(*args,**kwargs)
|
||||
|
||||
if records:
|
||||
# sex
|
||||
thesexes = [record.sex for record in records]
|
||||
thesexes = list(set(thesexes))
|
||||
|
||||
if len(thesexes)<= 1:
|
||||
del self.fields['sex']
|
||||
else:
|
||||
sexchoices = []
|
||||
for choice in self.fields['sex'].choices:
|
||||
if choice[0] in thesexes:
|
||||
sexchoices.append(choice)
|
||||
self.fields['sex'].choices = sexchoices
|
||||
|
||||
# boatclass
|
||||
theboatclasses = [record.boatclass for record in records]
|
||||
theboatclasses = list(set(theboatclasses))
|
||||
|
||||
if len(theboatclasses)<= 1:
|
||||
del self.fields['boatclass']
|
||||
else:
|
||||
boatclasschoices = []
|
||||
for choice in self.fields['boatclass'].choices:
|
||||
if choice[0] in theboatclasses:
|
||||
boatclasschoices.append(choice)
|
||||
self.fields['boatclass'].choices = boatclasschoices
|
||||
|
||||
# boattype
|
||||
theboattypees = [record.boattype for record in records]
|
||||
theboattypees = list(set(theboattypees))
|
||||
|
||||
if len(theboattypees)<= 1:
|
||||
del self.fields['boattype']
|
||||
else:
|
||||
boattypechoices = []
|
||||
for choice in self.fields['boattype'].choices:
|
||||
if choice[0] in theboattypees:
|
||||
boattypechoices.append(choice)
|
||||
self.fields['boattype'].choices = boattypechoices
|
||||
|
||||
# weightcategory
|
||||
theweightcategoryes = [record.weightcategory for record in records]
|
||||
theweightcategoryes = list(set(theweightcategoryes))
|
||||
|
||||
if len(theweightcategoryes)<= 1:
|
||||
del self.fields['weightcategory']
|
||||
else:
|
||||
weightcategorychoices = []
|
||||
for choice in self.fields['weightcategory'].choices:
|
||||
if choice[0] in theweightcategoryes:
|
||||
weightcategorychoices.append(choice)
|
||||
self.fields['weightcategory'].choices = weightcategorychoices
|
||||
|
||||
class WorkoutRaceSelectForm(forms.Form):
|
||||
# evaluate_after = forms.TimeField(
|
||||
# input_formats=['%H:%M:%S.%f',
|
||||
|
||||
Reference in New Issue
Block a user