box chart now uses StatsOptionsForm
This commit is contained in:
160
rowers/views.py
160
rowers/views.py
@@ -5945,6 +5945,11 @@ def user_boxplot_select(request,
|
||||
successmessage='',
|
||||
startdate=timezone.now()-datetime.timedelta(days=30),
|
||||
enddate=timezone.now()+datetime.timedelta(days=1),
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'workouttypes':['rower','dynamic','slides'],
|
||||
'waterboattype':['1x','2x','2-','4x','4-','8+']
|
||||
},
|
||||
userid=0):
|
||||
|
||||
if userid == 0:
|
||||
@@ -5955,6 +5960,27 @@ def user_boxplot_select(request,
|
||||
|
||||
r = getrower(user)
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
|
||||
try:
|
||||
workouttypes = options['workouttypes']
|
||||
except KeyError:
|
||||
workouttypes = ['rower','dynamic','slides']
|
||||
|
||||
try:
|
||||
includereststrokes = options['includereststrokes']
|
||||
except KeyError:
|
||||
includereststrokes = False
|
||||
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
checktypes = ['water','rower','dynamic','slides','skierg',
|
||||
'paddle','snow','other','coastal']
|
||||
waterboattype = ['1x','2x','2-','4x','4-','8+']
|
||||
|
||||
if 'startdate' in request.session:
|
||||
startdate = iso8601.parse_date(request.session['startdate'])
|
||||
|
||||
@@ -5962,22 +5988,23 @@ def user_boxplot_select(request,
|
||||
if 'enddate' in request.session:
|
||||
enddate = iso8601.parse_date(request.session['enddate'])
|
||||
|
||||
if startdatestring != "":
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
|
||||
if 'waterboattype' in request.session:
|
||||
waterboattype = request.session['waterboattype']
|
||||
else:
|
||||
waterboattype = ['1x','2x','2-','4x','4-','8+']
|
||||
if enddatestring != "":
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
|
||||
|
||||
if 'modalities' in request.session:
|
||||
modalities = request.session['modalities']
|
||||
if len(modalities) > 1:
|
||||
modality = 'all'
|
||||
else:
|
||||
modality = modalities[0]
|
||||
else:
|
||||
modalities = [m[0] for m in types.workouttypes]
|
||||
modality = 'all'
|
||||
if enddate < startdate:
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
|
||||
if 'startdate' in request.session:
|
||||
startdate = iso8601.parse_date(request.session['startdate'])
|
||||
|
||||
|
||||
if 'enddate' in request.session:
|
||||
enddate = iso8601.parse_date(request.session['enddate'])
|
||||
|
||||
if request.method == 'POST' and 'daterange' in request.POST:
|
||||
dateform = DateRangeForm(request.POST)
|
||||
@@ -5994,22 +6021,22 @@ def user_boxplot_select(request,
|
||||
'enddate':enddate,
|
||||
})
|
||||
|
||||
if request.method == 'POST' and 'modality' in request.POST:
|
||||
modalityform = TrendFlexModalForm(request.POST)
|
||||
if modalityform.is_valid():
|
||||
modality = modalityform.cleaned_data['modality']
|
||||
waterboattype = modalityform.cleaned_data['waterboattype']
|
||||
if modality == 'all':
|
||||
modalities = [m[0] for m in types.workouttypes]
|
||||
else:
|
||||
modalities = [modality]
|
||||
if request.method == 'POST' and 'optionsform' in request.POST:
|
||||
optionsform = StatsOptionsForm(request.POST)
|
||||
if optionsform.is_valid():
|
||||
workouttypes = []
|
||||
waterboattype = optionsform.cleaned_data['waterboattype']
|
||||
for type in checktypes:
|
||||
if optionsform.cleaned_data[type]:
|
||||
workouttypes.append(type)
|
||||
|
||||
if modality != 'water':
|
||||
waterboattype = [b[0] for b in types.boattypes]
|
||||
options = {
|
||||
'workouttypes':workouttypes,
|
||||
'waterboattype':waterboattype,
|
||||
}
|
||||
request.session['options'] = options
|
||||
print options
|
||||
|
||||
|
||||
request.session['modalities'] = modalities
|
||||
request.session['waterboattype'] = waterboattype
|
||||
|
||||
startdate = datetime.datetime.combine(startdate,datetime.time())
|
||||
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
|
||||
@@ -6030,10 +6057,31 @@ def user_boxplot_select(request,
|
||||
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)
|
||||
waterinclude = False
|
||||
if 'water' in workouttypes:
|
||||
waterinclude = True
|
||||
workoutsw = Workout.objects.filter(user=r,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
workouttype='water',
|
||||
).exclude(boattype__in=negtypes)
|
||||
workouttypes = [w for w in workouttypes if w != 'water']
|
||||
|
||||
workoutse = Workout.objects.filter(user=r,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
workouttype__in=workouttypes)
|
||||
|
||||
if waterinclude:
|
||||
workouts = workoutse | workoutsw
|
||||
workouts = workouts.distinct().order_by("-date", "-starttime")
|
||||
else:
|
||||
workouts = workoutse.order_by("-date","-starttime")
|
||||
|
||||
if waterinclude:
|
||||
workouttypes.append('water')
|
||||
|
||||
|
||||
|
||||
query = request.GET.get('q')
|
||||
if query:
|
||||
@@ -6049,11 +6097,18 @@ def user_boxplot_select(request,
|
||||
form.fields["workouts"].queryset = workouts
|
||||
|
||||
chartform = BoxPlotChoiceForm()
|
||||
modalityform = TrendFlexModalForm(initial={
|
||||
'modality':modality,
|
||||
'waterboattype':waterboattype
|
||||
})
|
||||
# set options form correctly
|
||||
initial = {}
|
||||
initial['waterboattype'] = waterboattype
|
||||
|
||||
for wtype in checktypes:
|
||||
if wtype in workouttypes:
|
||||
initial[wtype] = True
|
||||
else:
|
||||
initial[wtype] = False
|
||||
|
||||
optionsform = StatsOptionsForm(initial=initial)
|
||||
|
||||
messages.info(request,successmessage)
|
||||
messages.error(request,message)
|
||||
|
||||
@@ -6070,7 +6125,7 @@ def user_boxplot_select(request,
|
||||
'theuser':user,
|
||||
'form':form,
|
||||
'chartform':chartform,
|
||||
'modalityform':modalityform,
|
||||
'optionsform':optionsform,
|
||||
'teams':get_my_teams(request.user),
|
||||
})
|
||||
|
||||
@@ -7388,6 +7443,7 @@ def cumstats(request,theuser=0,
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
|
||||
try:
|
||||
workouttypes = options['workouttypes']
|
||||
@@ -7497,11 +7553,31 @@ def cumstats(request,theuser=0,
|
||||
|
||||
try:
|
||||
r2 = getrower(theuser)
|
||||
allergworkouts = Workout.objects.filter(user=r2,
|
||||
workouttype__in=workouttypes,
|
||||
boattype__in=waterboattype,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate)
|
||||
waterinclude = False
|
||||
if 'water' in workouttypes:
|
||||
waterinclude = True
|
||||
workoutsw = Workout.objects.filter(user=r2,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
workouttype='water',
|
||||
boattype__in='waterboattype'
|
||||
)
|
||||
workouttypes = [w for w in workouttypes if w != 'water']
|
||||
|
||||
workoutse = Workout.objects.filter(user=r2,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
workouttype__in=workouttypes)
|
||||
|
||||
if waterinclude:
|
||||
allergworkouts = workoutse | workoutsw
|
||||
allergworkouts = workouts.distinct().order_by("-date", "-starttime")
|
||||
else:
|
||||
allergworkouts = workoutse.order_by("-date","-starttime")
|
||||
|
||||
if waterinclude:
|
||||
workouttypes.append('water')
|
||||
|
||||
|
||||
except Rower.DoesNotExist:
|
||||
allergworkouts = []
|
||||
|
||||
Reference in New Issue
Block a user