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))

View File

@@ -2969,6 +2969,14 @@ class VirtualRaceResult(models.Model):
u2 = rr.user.last_name,
)
if self.teamname:
if self.entrycategory:
return u'Entry for {n} for "{r}" in {g} with {t}'.format(
n = name,
r = self.race,
g = self.entrycategory,
t = self.teamname,
)
return u'Entry for {n} for "{r}" in {c} {d} with {t} ({s})'.format(
n = name,
r = self.race,
@@ -2978,6 +2986,12 @@ class VirtualRaceResult(models.Model):
s = self.sex,
)
else:
if self.entrycategory:
return u'Entry for {n} for "{r}" in {g}'.format(
n = name,
r = self.race,
g = self.entrycategory,
)
return u'Entry for {n} for "{r}" in {c} {d} ({s})'.format(
n = name,
r = self.race,
@@ -3031,6 +3045,13 @@ class IndoorVirtualRaceResult(models.Model):
u2 = rr.user.last_name,
)
if self.teamname:
if self.entrycategory:
return u'Entry for {n} for "{r}" in {g} with {t}'.format(
n = name,
r = self.race,
g = self.entrycategory,
t = self.teamname,
)
return u'Entry for {n} for "{r}" on {c} with {t} ({s})'.format(
n = name,
r = self.race,
@@ -3039,6 +3060,12 @@ class IndoorVirtualRaceResult(models.Model):
s = self.sex,
)
else:
if self.entrycategory:
return u'Entry for {n} for "{r}" in {g}'.format(
n = name,
r = self.race,
g = self.entrycategory,
)
return u'Entry for {n} for "{r}" on {c} ({s})'.format(
n = name,
r = self.race,

View File

@@ -37,7 +37,7 @@
</p>
{% if race.coursestandards %}
<p>This race uses standard times and limits the race groups to those where
standard times exist. The "Field" form choice will overrule other selections you
standard times exist. The "Group" form choice will overrule other selections you
make in the form (boat type, weight, etc) and your entry will be rejected
if the age and gender doesn't match.
</p>

View File

@@ -1127,6 +1127,11 @@ def virtualevent_view(request,id=0):
except KeyError:
adaptiveclass = ['None','PR1','PR2','PR3','FES']
try:
entrycategory = cd['entrycategory']
except KeyError:
entrycategory = None
if race.sessiontype == 'race':
results = resultobj.objects.filter(
race=race,
@@ -1137,7 +1142,7 @@ def virtualevent_view(request,id=0):
weightcategory__in=weightcategory,
adaptiveclass__in=adaptiveclass,
age__gte=age_min,
age__lte=age_max
age__lte=age_max,
).order_by("duration")
else:
results = resultobj.objects.filter(
@@ -1148,9 +1153,12 @@ def virtualevent_view(request,id=0):
weightcategory__in=weightcategory,
adaptiveclass__in=adaptiveclass,
age__gte=age_min,
age__lte=age_max
age__lte=age_max,
).order_by("duration","-distance")
if entrycategory is not None:
results = results.filter(entrycategory__in=entrycategory)
# to-do - add DNS
dns = []