diff --git a/rowers/forms.py b/rowers/forms.py index 77b118a9..bd7c7ae1 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -522,30 +522,30 @@ class TrendFlexModalForm(forms.Form): waterboattype = forms.MultipleChoiceField(choices=boattypes, label='Water Boat Type', initial = types.waterboattype) - + rankingonly = forms.BooleanField(initial=False, + label='Only Ranking Pieces', + required=True) + # This form sets options for the summary stats page class StatsOptionsForm(forms.Form): includereststrokes = forms.BooleanField(initial=False,label='Include Rest Strokes',required=False) + rankingonly = forms.BooleanField(initial=False, + label='Only Ranking Pieces',required=True) water = forms.BooleanField(initial=False,required=False) waterboattype = forms.MultipleChoiceField(choices=boattypes, label='Water Boat Type', widget=forms.CheckboxSelectMultiple(), initial = types.waterboattype) + + + def __init__(self, *args, **kwargs): super(StatsOptionsForm, self).__init__(*args,**kwargs) for type in types.checktypes: self.fields[type] = forms.BooleanField(initial=True,required=False) -# rower = forms.BooleanField(initial=True,required=False) -# dynamic = forms.BooleanField(initial=True,required=False) -# slides = forms.BooleanField(initial=True,required=False) -# skierg = forms.BooleanField(initial=False,required=False) -# paddle = forms.BooleanField(initial=False,required=False) -# snow = forms.BooleanField(initial=False,required=False) -# coastal = forms.BooleanField(initial=False,required=False) -# other = forms.BooleanField(initial=False,required=False) class CourseSelectForm(forms.Form): course = forms.ModelChoiceField(queryset=GeoCourse.objects.all()) @@ -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', diff --git a/rowers/models.py b/rowers/models.py index 8f6ebcac..b2f26e18 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -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, ) diff --git a/rowers/templates/virtualevent.html b/rowers/templates/virtualevent.html index 8968233f..c1e22e52 100644 --- a/rowers/templates/virtualevent.html +++ b/rowers/templates/virtualevent.html @@ -242,6 +242,8 @@ {{ coursescript|safe }}
+ + {% if form %}
No erg pieces uploaded for this date range.
' + div = 'No pieces uploaded for this date range.
' scripta = script.split('\n')[2:-1] script = ''.join(scripta) @@ -3070,7 +3080,8 @@ def cum_flex(request,theuser=0, options={ 'includereststrokes':False, 'workouttypes':[i[0] for i in types.workouttypes], - 'waterboattype':types.waterboattype + 'waterboattype':types.waterboattype, + 'rankingonly':False, }): if 'options' in request.session: @@ -3086,6 +3097,11 @@ def cum_flex(request,theuser=0, except KeyError: includereststrokes = False + try: + rankingonly = options['rankingonly'] + except KeyError: + rankingonly = False + try: waterboattype = options['waterboattype'] except KeyError: @@ -3093,10 +3109,6 @@ def cum_flex(request,theuser=0, workstrokesonly = not includereststrokes - -# checktypes = ['water','rower','dynamic','slides','skierg', -# 'paddle','snow','coastal','other'] - if deltadays>0: startdate = enddate-datetime.timedelta(days=int(deltadays)) @@ -3130,8 +3142,6 @@ def cum_flex(request,theuser=0, if result: promember=1 - #if not promember: - #return HttpResponseRedirect("/rowers/about/") # get all indoor rows of in date range @@ -3170,6 +3180,7 @@ def cum_flex(request,theuser=0, optionsform = StatsOptionsForm(request.POST) if optionsform.is_valid(): includereststrokes = optionsform.cleaned_data['includereststrokes'] + rankingonly = optionsform.cleaned_data['rankingonly'] workstrokesonly = not includereststrokes waterboattype = optionsform.cleaned_data['waterboattype'] workouttypes = [] @@ -3182,6 +3193,7 @@ def cum_flex(request,theuser=0, 'includereststrokes':includereststrokes, 'workouttypes':workouttypes, 'waterboattype':waterboattype, + 'rankingonly':rankingonly, } request.session['options'] = options form = DateRangeForm(initial={ @@ -3216,7 +3228,7 @@ def cum_flex(request,theuser=0, # set options form correctly initial = {} initial['includereststrokes'] = includereststrokes - + initial['rankingonly'] = rankingonly initial['waterboattype'] = waterboattype for wtype in types.checktypes: @@ -3235,6 +3247,7 @@ def cum_flex(request,theuser=0, options['includereststrokes'] = includereststrokes + options['rankingonly'] = includereststrokes options['workouttypes'] =workouttypes options['waterboattype'] =waterboattype options['theuser'] =theuser @@ -5730,6 +5743,11 @@ def user_multiflex_select(request, else: waterboattype = types.waterboattype + if 'rankingonly' in request.session: + rankingonly = request.session['rankingonly'] + else: + rankingonly = False + if 'modalities' in request.session: modalities = request.session['modalities'] @@ -5761,6 +5779,7 @@ def user_multiflex_select(request, if modalityform.is_valid(): modality = modalityform.cleaned_data['modality'] waterboattype = modalityform.cleaned_data['waterboattype'] + rankingonly = modalityform.cleaned_data['rankingonly'] if modality == 'all': modalities = [m[0] for m in types.workouttypes] else: @@ -5772,7 +5791,7 @@ def user_multiflex_select(request, request.session['modalities'] = modalities request.session['waterboattype'] = waterboattype - + request.session['rankingonly'] = rankingonly startdate = datetime.datetime.combine(startdate,datetime.time()) enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) @@ -5793,11 +5812,23 @@ def user_multiflex_select(request, for b in types.boattypes: if b[0] not in waterboattype: negtypes.append(b[0]) - - workouts = Workout.objects.filter(user=r, - startdatetime__gte=startdate, - startdatetime__lte=enddate, - workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes) + + if rankingonly: + rankingpiece = [True] + else: + rankingpiece = [True,False] + + workouts = Workout.objects.filter( + user=r, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + workouttype__in=modalities, + rankingpiece__in=rankingpiece + ).order_by( + "-date", "-starttime" + ).exclude( + boattype__in=negtypes + ) query = request.GET.get('q') if query: @@ -6222,7 +6253,8 @@ def user_boxplot_select(request, options={ 'includereststrokes':False, 'workouttypes':['rower','dynamic','slides'], - 'waterboattype':types.waterboattype + 'waterboattype':types.waterboattype, + 'rankingonly':False, }, userid=0): @@ -6238,6 +6270,11 @@ def user_boxplot_select(request, except KeyError: workouttypes = ['rower','dynamic','slides'] + try: + rankingonly = options['rankingonly'] + except KeyError: + rankingonly = False + try: includereststrokes = options['includereststrokes'] except KeyError: @@ -6246,8 +6283,6 @@ def user_boxplot_select(request, workstrokesonly = not includereststrokes -# checktypes = ['water','rower','dynamic','slides','skierg', -# 'paddle','snow','other','coastal'] waterboattype = types.waterboattype if 'startdate' in request.session: @@ -6295,6 +6330,7 @@ def user_boxplot_select(request, if optionsform.is_valid(): workouttypes = [] waterboattype = optionsform.cleaned_data['waterboattype'] + rankingonly = optionsform.cleaned_data['rankingonly'] for type in types.checktypes: if optionsform.cleaned_data[type]: workouttypes.append(type) @@ -6302,6 +6338,7 @@ def user_boxplot_select(request, options = { 'workouttypes':workouttypes, 'waterboattype':waterboattype, + 'rankingonly':rankingonly, } request.session['options'] = options @@ -6325,20 +6362,31 @@ def user_boxplot_select(request, if b[0] not in waterboattype: negtypes.append(b[0]) + if rankingonly: + rankingpiece = [True] + else: + rankingpiece = [True,False] + waterinclude = False - if 'water' in workouttypes: - waterinclude = True + + for ttype in types.otwtypes: + if ttype in workouttypes: + waterinclude = True + + if waterinclude: workoutsw = Workout.objects.filter(user=r, startdatetime__gte=startdate, startdatetime__lte=enddate, - workouttype='water', + workouttype__in=types.otwtypes, + rankingpiece__in=rankingpiece, ).exclude(boattype__in=negtypes) - workouttypes = [w for w in workouttypes if w != 'water'] + workouttypes = [w for w in workouttypes if w not in types.otwtypes] workoutse = Workout.objects.filter(user=r, startdatetime__gte=startdate, startdatetime__lte=enddate, - workouttype__in=workouttypes) + workouttype__in=workouttypes, + rankingpiece__in=rankingpiece) if waterinclude: workouts = workoutse | workoutsw @@ -6347,9 +6395,8 @@ def user_boxplot_select(request, workouts = workoutse.order_by("-date","-starttime") if waterinclude: - workouttypes.append('water') - - + for ttype in types.otwtypes: + workouttypes.append(ttype) query = request.GET.get('q') if query: @@ -7710,7 +7757,8 @@ def cumstats(request,theuser=0, options={ 'includereststrokes':False, 'workouttypes':['rower','dynamic','slides'], - 'waterboattype':types.waterboattype + 'waterboattype':types.waterboattype, + 'rankingonly':False, }): if 'options' in request.session: @@ -7728,10 +7776,13 @@ def cumstats(request,theuser=0, includereststrokes = False + try: + rankingonly = options['rankingonly'] + except KeyError: + rankingonly = False + workstrokesonly = not includereststrokes -# checktypes = ['water','rower','dynamic','slides','skierg', -# 'paddle','snow','other','coastal'] waterboattype = types.waterboattype if deltadays>0: @@ -7807,6 +7858,7 @@ def cumstats(request,theuser=0, includereststrokes = optionsform.cleaned_data['includereststrokes'] workstrokesonly = not includereststrokes workouttypes = [] + rankingonly = optionsform.cleaned_data['rankingonly'] waterboattype = optionsform.cleaned_data['waterboattype'] for type in types.checktypes: if optionsform.cleaned_data[type]: @@ -7816,6 +7868,7 @@ def cumstats(request,theuser=0, 'includereststrokes':includereststrokes, 'workouttypes':workouttypes, 'waterboattype':waterboattype, + 'rankingonly':rankingonly, } request.session['options'] = options form = DateRangeForm() @@ -7833,21 +7886,32 @@ def cumstats(request,theuser=0, try: r2 = getrower(theuser) + if rankingonly: + rankingpiece = [True] + else: + rankingpiece = [True,False] + waterinclude = False - if 'water' in workouttypes: - waterinclude = True + + for ttype in types.otwtypes: + if ttype in workouttypes: + waterinclude = True + + if waterinclude: workoutsw = Workout.objects.filter(user=r2, startdatetime__gte=startdate, startdatetime__lte=enddate, workouttype='water', - boattype__in='waterboattype' + boattype__in='waterboattype', + rankingpiece__in=rankingpiece, ) workouttypes = [w for w in workouttypes if w != 'water'] workoutse = Workout.objects.filter(user=r2, startdatetime__gte=startdate, startdatetime__lte=enddate, - workouttype__in=workouttypes) + workouttype__in=workouttypes, + rankingpiece__in=rankingpiece) if waterinclude: allergworkouts = workoutse | workoutsw @@ -7856,7 +7920,9 @@ def cumstats(request,theuser=0, allergworkouts = workoutse.order_by("-date","-starttime") if waterinclude: - workouttypes.append('water') + for ttype in types.otwtypes: + workouttypes.append(ttype) + except Rower.DoesNotExist: @@ -10614,6 +10680,7 @@ def workout_upload_view(request, else: messages.error(request,message) + if landingpage != 'workout_upload_view': url = reverse(landingpage, kwargs = { @@ -13634,6 +13701,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 +13728,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 +13779,16 @@ 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") + if results: + form = RaceResultFilterForm(records=records) + else: + form = None + # to-do - add DNS dns = [] if timezone.now() > race.evaluation_closure: @@ -13708,10 +13799,6 @@ def virtualevent_view(request,id=0): - records = VirtualRaceResult.objects.filter( - race=race - ) - return render(request,'virtualevent.html', { @@ -13801,14 +13888,25 @@ def virtualevent_addboat_view(request,id=0): sex = 'male' if boattype in boattypes and boatclass in boatclasses: - messages.error(request,"You have already registered in that boat class/type") - url = reverse(virtualevent_view, - kwargs = { - 'id': race.id + # check if different sexes + therecords = records.filter( + boattype=boattype, + boatclass=boatclass) + + thesexes = [record.sex for record in therecords] + if sex in thesexes: + + messages.error( + request, + "You have already registered in that boat class/type" + ) + url = reverse(virtualevent_view, + kwargs = { + 'id': race.id } ) - return HttpResponseRedirect(url) + return HttpResponseRedirect(url) record = VirtualRaceResult( userid=r.id,