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', label='Weight Category',
initial=['hwt','lwt'], initial=['hwt','lwt'],
widget=forms.CheckboxSelectMultiple()) 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): class WorkoutRaceSelectForm(forms.Form):
# evaluate_after = forms.TimeField( # evaluate_after = forms.TimeField(
# input_formats=['%H:%M:%S.%f', # input_formats=['%H:%M:%S.%f',

View File

@@ -1641,10 +1641,11 @@ class VirtualRaceResult(models.Model):
u1 = rr.user.first_name, u1 = rr.user.first_name,
u2 = rr.user.last_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, n = name,
r = self.race, r = self.race,
d = self.boattype, d = self.boattype,
c = self.boatclass,
) )

View File

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