From cd3ee722e21a695bef9d0fcfb4ae0e74db16b6c9 Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Fri, 8 Jun 2018 10:44:42 +0200
Subject: [PATCH 1/5] improved filter form
---
rowers/forms.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++-
rowers/models.py | 3 ++-
rowers/views.py | 39 ++++++++++++++++++++++---------
3 files changed, 90 insertions(+), 13 deletions(-)
diff --git a/rowers/forms.py b/rowers/forms.py
index 77b118a9..11c64220 100644
--- a/rowers/forms.py
+++ b/rowers/forms.py
@@ -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/views.py b/rowers/views.py
index ae26b810..143de466 100644
--- a/rowers/views.py
+++ b/rowers/views.py
@@ -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',
{
From 8d580a3ae86bfaa0e3bec3b640e1fd0b6ade4bd7 Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Fri, 8 Jun 2018 10:55:49 +0200
Subject: [PATCH 2/5] bug fix
---
rowers/views.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/rowers/views.py b/rowers/views.py
index 143de466..78020904 100644
--- a/rowers/views.py
+++ b/rowers/views.py
@@ -10614,6 +10614,7 @@ def workout_upload_view(request,
else:
messages.error(request,message)
+
if landingpage != 'workout_upload_view':
url = reverse(landingpage,
kwargs = {
From 85ebdd3ba0f7510d785239e61f822d6aff25cf1c Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Fri, 8 Jun 2018 11:40:34 +0200
Subject: [PATCH 3/5] removed filter form if no results
---
rowers/templates/virtualevent.html | 3 +++
rowers/views.py | 7 +++++--
2 files changed, 8 insertions(+), 2 deletions(-)
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 %}
Filter Results
@@ -253,6 +255,7 @@
{% csrf_token %}
+ {% endif %}
diff --git a/rowers/views.py b/rowers/views.py
index 78020904..54c9f3ed 100644
--- a/rowers/views.py
+++ b/rowers/views.py
@@ -13718,8 +13718,11 @@ def virtualevent_view(request,id=0):
workoutid__isnull=False,
).order_by("duration")
- form = RaceResultFilterForm(records=records)
-
+ if results:
+ form = RaceResultFilterForm(records=records)
+ else:
+ form = None
+
# to-do - add DNS
dns = []
if timezone.now() > race.evaluation_closure:
From a6a564559c4c9b5bbe2fa2984bc044ae5620ace1 Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Fri, 8 Jun 2018 13:55:38 +0200
Subject: [PATCH 4/5] added ranking only options
---
rowers/forms.py | 18 +++----
rowers/views.py | 138 +++++++++++++++++++++++++++++++++++-------------
2 files changed, 111 insertions(+), 45 deletions(-)
diff --git a/rowers/forms.py b/rowers/forms.py
index 11c64220..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())
diff --git a/rowers/views.py b/rowers/views.py
index 54c9f3ed..4c94ef91 100644
--- a/rowers/views.py
+++ b/rowers/views.py
@@ -2969,6 +2969,7 @@ def cum_flex_data(
request,
options={
'includereststrokes':False,
+ 'rankingonly':False,
'workouttypes':[i[0] for i in types.workouttypes],
'waterboattype':types.waterboattype,
'theuser':0,
@@ -2984,6 +2985,7 @@ def cum_flex_data(
options = request.session['options']
workouttypes = options['workouttypes']
+ rankingonly = options['rankingonly']
includereststrokes = options['includereststrokes']
waterboattype = options['waterboattype']
workstrokesonly = not includereststrokes
@@ -3026,23 +3028,31 @@ def cum_flex_data(
promember=1
r2 = getrower(theuser)
+
+ if rankingonly:
+ rankingpiece = [True,]
+ else:
+ rankingpiece = [True,False]
+
allworkouts = Workout.objects.filter(user=r2,
workouttype__in=workouttypes,
boattype__in=waterboattype,
startdatetime__gte=startdate,
- startdatetime__lte=enddate)
+ startdatetime__lte=enddate,
+ rankingpiece__in=rankingpiece)
if allworkouts:
res = interactive_cum_flex_chart2(allworkouts,xparam=xparam,
yparam1=yparam1,
yparam2=yparam2,
promember=promember,
- workstrokesonly=workstrokesonly)
+ workstrokesonly=workstrokesonly,
+ rankingpiece__in=rankingpiece)
script = res[0]
div = res[1]
else:
script = ''
- div = '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:
From 31627c3e86c416688cbb8e9c7fb2e504c257a4ef Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Tue, 12 Jun 2018 12:21:53 +0200
Subject: [PATCH 5/5] can now register in one boat class/type with M/F and
mixed
---
rowers/views.py | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/rowers/views.py b/rowers/views.py
index 4c94ef91..acf450f5 100644
--- a/rowers/views.py
+++ b/rowers/views.py
@@ -13888,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,