diff --git a/rowers/forms.py b/rowers/forms.py index 7e9fff79..b5dea6d3 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -702,7 +702,43 @@ class WorkoutSessionSelectForm(forms.Form): initial=workoutdata['initial'], widget = forms.CheckboxSelectMultiple, ) - + + + +class RaceResultFilterForm(forms.Form): + sexchoices = ( + ('female','Female'), + ('male','Male'), + ('mixed','Mixed'), + ) + + weightcategories = ( + ('hwt','heavy-weight'), + ('lwt','light-weight'), + ) + + + sex = forms.MultipleChoiceField( + choices=sexchoices, + initial=['male','female','mixed'], + label='Gender', + widget=forms.CheckboxSelectMultiple()) + + boattype = forms.MultipleChoiceField( + choices=boattypes, + label='Boat Type', + initial=['1x','2x','2-','4x','4-','8+'], + widget=forms.CheckboxSelectMultiple()) + + age_min = forms.IntegerField(label='Min Age',initial=16) + age_max = forms.IntegerField(label='Max Age',initial=100) + + weightcategory = forms.MultipleChoiceField( + choices=weightcategories, + label='Weight Category', + initial=['hwt','lwt'], + widget=forms.CheckboxSelectMultiple()) + class WorkoutRaceSelectForm(forms.Form): # evaluate_after = forms.TimeField( # input_formats=['%H:%M:%S.%f', diff --git a/rowers/templates/virtualevent.html b/rowers/templates/virtualevent.html index 071567cd..808dfde1 100644 --- a/rowers/templates/virtualevent.html +++ b/rowers/templates/virtualevent.html @@ -230,10 +230,24 @@
+

Course

{{ coursediv|safe }} {{ coursescript|safe }} + +

+

+

Filter Results

+ +
+ + {{ form.as_table }} +
+ + {% csrf_token %} + +

diff --git a/rowers/views.py b/rowers/views.py index b23d6137..aa83404e 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -36,6 +36,7 @@ from rowers.forms import ( LandingPageForm,PlannedSessionSelectForm,WorkoutSessionSelectForm, PlannedSessionTeamForm,PlannedSessionTeamMemberForm, VirtualRaceSelectForm,WorkoutRaceSelectForm,CourseSelectForm, + RaceResultFilterForm, ) from django.core.urlresolvers import reverse from django.core.exceptions import PermissionDenied @@ -13439,6 +13440,7 @@ def virtualevent_view(request,id=0): else: r = None + try: race = VirtualRace.objects.get(id=id) except VirtualRace.DoesNotExist: @@ -13467,17 +13469,52 @@ def virtualevent_view(request,id=0): if race_can_edit(r,race): buttons += ['editbutton'] - results = VirtualRaceResult.objects.filter( - race=race, - workoutid__isnull=False, - ).order_by("duration") + if request.method == 'POST': + form = RaceResultFilterForm(request.POST) + if form.is_valid(): + cd = form.cleaned_data + sex = cd['sex'] + boattype = cd['boattype'] + age_min = cd['age_min'] + age_max = cd['age_max'] + weightcategory = cd['weightcategory'] - # to-do - add DNS - dns = [] - if timezone.now() > race.evaluation_closure: - dns = VirtualRaceResult.objects.filter( + results = VirtualRaceResult.objects.filter( + race=race, + workoutid__isnull=False, + boattype__in=boattype, + sex__in=sex, + weightcategory__in=weightcategory, + age__gte=age_min, + age__lte=age_max + ).order_by("duration") + + # to-do - add DNS + dns = [] + if timezone.now() > race.evaluation_closure: + dns = VirtualRaceResult.objects.filter( + race=race, + workoutid__isnull=True, + boattype__in=boattype, + sex__in=sex, + weightcategory__in=weightcategory, + age__gte=age_min, + age__lte=age_max + ) + else: + form = RaceResultFilterForm() + + results = VirtualRaceResult.objects.filter( race=race, - workoutid__isnull=True, + workoutid__isnull=False, + ).order_by("duration") + + # to-do - add DNS + dns = [] + if timezone.now() > race.evaluation_closure: + dns = VirtualRaceResult.objects.filter( + race=race, + workoutid__isnull=True, ) @@ -13497,6 +13534,7 @@ def virtualevent_view(request,id=0): 'buttons':buttons, 'dns':dns, 'records':records, + 'form':form, }) @login_required()