box chart now uses StatsOptionsForm
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
// Get the form fields and hidden div
|
// Get the form fields and hidden div
|
||||||
var modality = $("#id_modality");
|
var checkbox = $("#id_water");
|
||||||
var hidden = $("#id_waterboattype");
|
var hidden = $("#id_waterboattype");
|
||||||
|
|
||||||
|
|
||||||
@@ -28,16 +28,14 @@
|
|||||||
|
|
||||||
hidden.hide();
|
hidden.hide();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Setup an event listener for when the state of the
|
// Setup an event listener for when the state of the
|
||||||
// checkbox changes.
|
// checkbox changes.
|
||||||
modality.change(function() {
|
checkbox.change(function() {
|
||||||
// Check to see if the checkbox is checked.
|
// Check to see if the checkbox is checked.
|
||||||
// If it is, show the fields and populate the input.
|
// If it is, show the fields and populate the input.
|
||||||
// If not, hide the fields.
|
// If not, hide the fields.
|
||||||
var Value = modality.val();
|
if (checkbox.is(':checked')) {
|
||||||
if (Value=='water') {
|
|
||||||
// Show the hidden fields.
|
// Show the hidden fields.
|
||||||
hidden.show();
|
hidden.show();
|
||||||
} else {
|
} else {
|
||||||
@@ -55,12 +53,7 @@
|
|||||||
// $("#hidden_field").val("");
|
// $("#hidden_field").val("");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@@ -119,12 +112,12 @@
|
|||||||
<div class="grid_4 alpha">
|
<div class="grid_4 alpha">
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
{{ modalityform.as_table }}
|
{{ optionsform.as_table }}
|
||||||
</table>
|
</table>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid_2 omega">
|
<div class="grid_2 omega">
|
||||||
<input name='modalityform' class="button green" type="submit" value="Submit">
|
<input name='optionsform' class="button green" type="submit" value="Submit">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
160
rowers/views.py
160
rowers/views.py
@@ -5945,6 +5945,11 @@ def user_boxplot_select(request,
|
|||||||
successmessage='',
|
successmessage='',
|
||||||
startdate=timezone.now()-datetime.timedelta(days=30),
|
startdate=timezone.now()-datetime.timedelta(days=30),
|
||||||
enddate=timezone.now()+datetime.timedelta(days=1),
|
enddate=timezone.now()+datetime.timedelta(days=1),
|
||||||
|
options={
|
||||||
|
'includereststrokes':False,
|
||||||
|
'workouttypes':['rower','dynamic','slides'],
|
||||||
|
'waterboattype':['1x','2x','2-','4x','4-','8+']
|
||||||
|
},
|
||||||
userid=0):
|
userid=0):
|
||||||
|
|
||||||
if userid == 0:
|
if userid == 0:
|
||||||
@@ -5955,6 +5960,27 @@ def user_boxplot_select(request,
|
|||||||
|
|
||||||
r = getrower(user)
|
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:
|
if 'startdate' in request.session:
|
||||||
startdate = iso8601.parse_date(request.session['startdate'])
|
startdate = iso8601.parse_date(request.session['startdate'])
|
||||||
|
|
||||||
@@ -5962,22 +5988,23 @@ def user_boxplot_select(request,
|
|||||||
if 'enddate' in request.session:
|
if 'enddate' in request.session:
|
||||||
enddate = iso8601.parse_date(request.session['enddate'])
|
enddate = iso8601.parse_date(request.session['enddate'])
|
||||||
|
|
||||||
|
if startdatestring != "":
|
||||||
|
startdate = iso8601.parse_date(startdatestring)
|
||||||
|
|
||||||
if 'waterboattype' in request.session:
|
if enddatestring != "":
|
||||||
waterboattype = request.session['waterboattype']
|
enddate = iso8601.parse_date(enddatestring)
|
||||||
else:
|
|
||||||
waterboattype = ['1x','2x','2-','4x','4-','8+']
|
|
||||||
|
|
||||||
|
if enddate < startdate:
|
||||||
if 'modalities' in request.session:
|
s = enddate
|
||||||
modalities = request.session['modalities']
|
enddate = startdate
|
||||||
if len(modalities) > 1:
|
startdate = s
|
||||||
modality = 'all'
|
|
||||||
else:
|
if 'startdate' in request.session:
|
||||||
modality = modalities[0]
|
startdate = iso8601.parse_date(request.session['startdate'])
|
||||||
else:
|
|
||||||
modalities = [m[0] for m in types.workouttypes]
|
|
||||||
modality = 'all'
|
if 'enddate' in request.session:
|
||||||
|
enddate = iso8601.parse_date(request.session['enddate'])
|
||||||
|
|
||||||
if request.method == 'POST' and 'daterange' in request.POST:
|
if request.method == 'POST' and 'daterange' in request.POST:
|
||||||
dateform = DateRangeForm(request.POST)
|
dateform = DateRangeForm(request.POST)
|
||||||
@@ -5994,22 +6021,22 @@ def user_boxplot_select(request,
|
|||||||
'enddate':enddate,
|
'enddate':enddate,
|
||||||
})
|
})
|
||||||
|
|
||||||
if request.method == 'POST' and 'modality' in request.POST:
|
if request.method == 'POST' and 'optionsform' in request.POST:
|
||||||
modalityform = TrendFlexModalForm(request.POST)
|
optionsform = StatsOptionsForm(request.POST)
|
||||||
if modalityform.is_valid():
|
if optionsform.is_valid():
|
||||||
modality = modalityform.cleaned_data['modality']
|
workouttypes = []
|
||||||
waterboattype = modalityform.cleaned_data['waterboattype']
|
waterboattype = optionsform.cleaned_data['waterboattype']
|
||||||
if modality == 'all':
|
for type in checktypes:
|
||||||
modalities = [m[0] for m in types.workouttypes]
|
if optionsform.cleaned_data[type]:
|
||||||
else:
|
workouttypes.append(type)
|
||||||
modalities = [modality]
|
|
||||||
|
|
||||||
if modality != 'water':
|
options = {
|
||||||
waterboattype = [b[0] for b in types.boattypes]
|
'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())
|
startdate = datetime.datetime.combine(startdate,datetime.time())
|
||||||
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
|
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:
|
if b[0] not in waterboattype:
|
||||||
negtypes.append(b[0])
|
negtypes.append(b[0])
|
||||||
|
|
||||||
workouts = Workout.objects.filter(user=r,
|
waterinclude = False
|
||||||
startdatetime__gte=startdate,
|
if 'water' in workouttypes:
|
||||||
startdatetime__lte=enddate,
|
waterinclude = True
|
||||||
workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes)
|
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')
|
query = request.GET.get('q')
|
||||||
if query:
|
if query:
|
||||||
@@ -6049,11 +6097,18 @@ def user_boxplot_select(request,
|
|||||||
form.fields["workouts"].queryset = workouts
|
form.fields["workouts"].queryset = workouts
|
||||||
|
|
||||||
chartform = BoxPlotChoiceForm()
|
chartform = BoxPlotChoiceForm()
|
||||||
modalityform = TrendFlexModalForm(initial={
|
# set options form correctly
|
||||||
'modality':modality,
|
initial = {}
|
||||||
'waterboattype':waterboattype
|
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.info(request,successmessage)
|
||||||
messages.error(request,message)
|
messages.error(request,message)
|
||||||
|
|
||||||
@@ -6070,7 +6125,7 @@ def user_boxplot_select(request,
|
|||||||
'theuser':user,
|
'theuser':user,
|
||||||
'form':form,
|
'form':form,
|
||||||
'chartform':chartform,
|
'chartform':chartform,
|
||||||
'modalityform':modalityform,
|
'optionsform':optionsform,
|
||||||
'teams':get_my_teams(request.user),
|
'teams':get_my_teams(request.user),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -7388,6 +7443,7 @@ def cumstats(request,theuser=0,
|
|||||||
|
|
||||||
if 'options' in request.session:
|
if 'options' in request.session:
|
||||||
options = request.session['options']
|
options = request.session['options']
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
workouttypes = options['workouttypes']
|
workouttypes = options['workouttypes']
|
||||||
@@ -7497,11 +7553,31 @@ def cumstats(request,theuser=0,
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
r2 = getrower(theuser)
|
r2 = getrower(theuser)
|
||||||
allergworkouts = Workout.objects.filter(user=r2,
|
waterinclude = False
|
||||||
workouttype__in=workouttypes,
|
if 'water' in workouttypes:
|
||||||
boattype__in=waterboattype,
|
waterinclude = True
|
||||||
startdatetime__gte=startdate,
|
workoutsw = Workout.objects.filter(user=r2,
|
||||||
startdatetime__lte=enddate)
|
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:
|
except Rower.DoesNotExist:
|
||||||
allergworkouts = []
|
allergworkouts = []
|
||||||
|
|||||||
Reference in New Issue
Block a user