Private
Public Access
1
0

filter form

This commit is contained in:
Sander Roosendaal
2020-05-28 06:49:13 +02:00
parent 98efddb8d7
commit 6914993516
4 changed files with 59 additions and 3 deletions

View File

@@ -1230,6 +1230,12 @@ class RaceResultFilterForm(forms.Form):
initial=['None','PR1','PR2','PR3','FES'],
widget=forms.CheckboxSelectMultiple())
entrycategory = forms.MultipleChoiceField(
choices = [],
label = 'Groups',
widget=forms.CheckboxSelectMultiple()
)
def __init__(self, *args, **kwargs):
if 'records' in kwargs:
records = kwargs.pop('records',None)
@@ -1237,6 +1243,21 @@ class RaceResultFilterForm(forms.Form):
super(RaceResultFilterForm,self).__init__(*args,**kwargs)
if records:
# group
thecategories = [record.entrycategory for record in records]
thecategories = list(set(thecategories))
if len(thecategories) <= 1:
del self.fields['entrycategory']
else:
categorychoices = []
for category in thecategories:
if category is not None:
categorychoices.append(
(category.id,category)
)
self.fields['entrycategory'].choices = categorychoices
self.fields['entrycategory'].initial = [cat[0] for cat in categorychoices]
# sex
thesexes = [record.sex for record in records]
thesexes = list(set(thesexes))