Private
Public Access
1
0

improved filter form

This commit is contained in:
Sander Roosendaal
2018-06-08 10:44:42 +02:00
parent 5603235f56
commit cd3ee722e2
3 changed files with 90 additions and 13 deletions

View File

@@ -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',

View File

@@ -1641,10 +1641,11 @@ class VirtualRaceResult(models.Model):
u1 = rr.user.first_name,
u2 = rr.user.last_name,
)
return u'Entry for {n} for "{r}" in {d}'.format(
return u'Entry for {n} for "{r}" in {c} {d}'.format(
n = name,
r = self.race,
d = self.boattype,
c = self.boatclass,
)

View File

@@ -13634,6 +13634,11 @@ def virtualevent_view(request,id=0):
script,div = course_map(race.course)
records = VirtualRaceResult.objects.filter(
race=race
)
buttons = []
if not request.user.is_anonymous():
@@ -13656,15 +13661,31 @@ def virtualevent_view(request,id=0):
buttons += ['editbutton']
if request.method == 'POST':
form = RaceResultFilterForm(request.POST)
form = RaceResultFilterForm(request.POST,records=records)
if form.is_valid():
cd = form.cleaned_data
sex = cd['sex']
boattype = cd['boattype']
boatclass = cd['boatclass']
try:
sex = cd['sex']
except KeyError:
sex = ['female','male','mixed']
try:
boattype = cd['boattype']
except KeyError:
boattype = types.waterboattype
try:
boatclass = cd['boatclass']
except KeyError:
boatclass = [t for t in types.otwtypes]
age_min = cd['age_min']
age_max = cd['age_max']
weightcategory = cd['weightcategory']
try:
weightcategory = cd['weightcategory']
except KeyError:
weightcategory = ['hwt','lwt']
results = VirtualRaceResult.objects.filter(
race=race,
@@ -13691,13 +13712,13 @@ def virtualevent_view(request,id=0):
age__lte=age_max
)
else:
form = RaceResultFilterForm()
results = VirtualRaceResult.objects.filter(
race=race,
workoutid__isnull=False,
).order_by("duration")
form = RaceResultFilterForm(records=records)
# to-do - add DNS
dns = []
if timezone.now() > race.evaluation_closure:
@@ -13708,10 +13729,6 @@ def virtualevent_view(request,id=0):
records = VirtualRaceResult.objects.filter(
race=race
)
return render(request,'virtualevent.html',
{