diff --git a/rowers/forms.py b/rowers/forms.py
index 2bb383e7..58f20188 100644
--- a/rowers/forms.py
+++ b/rowers/forms.py
@@ -7,12 +7,38 @@ from django.contrib.auth.models import User
from django.contrib.admin.widgets import AdminDateWidget
from django.forms.extras.widgets import SelectDateWidget
from django.utils import timezone,translation
-from django.forms import ModelForm
+from django.forms import ModelForm, Select
import dataprep
import types
import datetime
from django.forms import formset_factory
from utils import landingpages
+from metrics import axes
+
+class SelectWidget(Select):
+ """
+ Subclass of Django's select widget that allows disabling options.
+ """
+ def __init__(self, *args, **kwargs):
+ self._disabled_choices = []
+ super(SelectWidget, self).__init__(*args, **kwargs)
+
+ @property
+ def disabled_choices(self):
+ return self._disabled_choices
+
+ @disabled_choices.setter
+ def disabled_choices(self, other):
+ self._disabled_choices = other
+
+ def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
+ option_dict = super(SelectWidget, self).create_option(
+ name, value, label, selected, index, subindex=subindex, attrs=attrs
+ )
+ if value in self.disabled_choices:
+ option_dict['attrs']['disabled'] = 'disabled'
+
+ return option_dict
# login form
class LoginForm(forms.Form):
@@ -29,6 +55,7 @@ class EmailForm(forms.Form):
message = forms.CharField()
+
# Upload the CrewNerd Summary CSV
class CNsummaryForm(forms.Form):
file = forms.FileField(required=True,validators=[must_be_csv])
@@ -919,3 +946,59 @@ class VirtualRaceSelectForm(forms.Form):
self.fields['country'] = forms.ChoiceField(
choices = get_countries(),initial='All'
)
+
+class FlexAxesForm(forms.Form):
+ axchoices = (
+ (ax[0],ax[1]) for ax in axes if ax[0] not in ['cumdist','None']
+ )
+
+
+ yaxchoices = (
+ (ax[0], ax[1]) for ax in axes if ax[0] not in ['cumdist','distance','time']
+ )
+
+ yaxchoices2 = (
+ (ax[0], ax[1]) for ax in axes if ax[0] not in ['cumdist','distance','time']
+ )
+
+
+ xaxis = forms.ChoiceField(
+ choices=axchoices,label='X-Axis',widget=SelectWidget,required=True)
+ yaxis1 = forms.ChoiceField(
+ choices=yaxchoices,label='Left Axis',widget=SelectWidget,required=True)
+ yaxis2 = forms.ChoiceField(
+ choices=yaxchoices2,label='Right Axis',widget=SelectWidget,required=True)
+
+ def __init__(self,request,*args,**kwargs):
+ super(FlexAxesForm, self).__init__(*args, **kwargs)
+
+ rower = Rower.objects.get(user=request.user)
+
+ axchoicespro = (
+ ('',ax[1]) if ax[4] == 'pro' and ax[0] else (ax[0],ax[1]) for ax in axes
+ )
+
+ axchoicesbasicx = []
+ axchoicesbasicy = []
+
+ for ax in axes:
+ if ax[4] != 'pro' and ax[0] != 'cumdist':
+ if ax[0] != 'None':
+ axchoicesbasicx.insert(0,(ax[0],ax[1]))
+ if ax[0] not in ['cumdist','distance','time']:
+ axchoicesbasicy.insert(0,(ax[0],ax[1]))
+ else:
+ if ax[0] != 'None':
+ axchoicesbasicx.insert(0,('None',ax[1]+' (PRO)'))
+ if ax[0] not in ['cumdist','distance','time']:
+ axchoicesbasicy.insert(0,('None',ax[1]+' (PRO)'))
+
+
+ if rower.rowerplan == 'basic':
+ self.fields['xaxis'].choices = axchoicesbasicx
+ self.fields['yaxis1'].choices = axchoicesbasicy
+ self.fields['yaxis2'].choices = axchoicesbasicy
+
+
+
+
diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py
index cfdb6ecd..5e383310 100644
--- a/rowers/interactiveplots.py
+++ b/rowers/interactiveplots.py
@@ -2803,6 +2803,8 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
),
plot])
+ layout.sizing_mode = 'scale_width'
+
script, div = components(layout)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
@@ -3002,8 +3004,6 @@ def interactive_flex_chart2(id=0,promember=0,
- sizing_mode = 'fixed' # 'scale_width' also looks nice with this example
-
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
tools=TOOLS,
toolbar_sticky=False
diff --git a/rowers/templates/cum_flex.html b/rowers/templates/cum_flex.html
index 9fd5a1e2..34b20dfe 100644
--- a/rowers/templates/cum_flex.html
+++ b/rowers/templates/cum_flex.html
@@ -81,147 +81,40 @@
- -
-
-
- -
-
Use this form to select a different date range:
-
- Select start and end date for a date range:
-
-
-
-
- -
+
-
Summary for {{ theuser.first_name }} {{ theuser.last_name }}
between {{ startdate|date }} and {{ enddate|date }}
- -
-
-
- -
-
-
- -
-
-
-
{{ the_div|safe }}
+ -
+
+ -
+
+
+ -
+
+ {{ flexaxesform.as_table }}
+
+
+ -
+ {% csrf_token %}
+
+
+
{% endblock %}
diff --git a/rowers/views.py b/rowers/views.py
index 1dd85aa4..04994b73 100644
--- a/rowers/views.py
+++ b/rowers/views.py
@@ -43,7 +43,7 @@ from rowers.forms import (
LandingPageForm,PlannedSessionSelectForm,WorkoutSessionSelectForm,
PlannedSessionTeamForm,PlannedSessionTeamMemberForm,
VirtualRaceSelectForm,WorkoutRaceSelectForm,CourseSelectForm,
- RaceResultFilterForm,PowerIntervalUpdateForm
+ RaceResultFilterForm,PowerIntervalUpdateForm,FlexAxesForm,
)
from django.core.urlresolvers import reverse, reverse_lazy
@@ -2448,6 +2448,12 @@ def histo_all(request,theuser=0,
'teams':get_my_teams(request.user),
})
+def keyvalue_get_default(key,options,def_options):
+ try:
+ return options[key]
+ except KeyError:
+ return def_options[key]
+
# The Flex plot for a large selection of workouts
@login_required()
def cum_flex_data(
@@ -2468,37 +2474,21 @@ def cum_flex_data(
def_options = options
+
if 'options' in request.session:
options = request.session['options']
- try:
- modality = options['modality']
- rankingonly = options['rankingonly']
- includereststrokes = options['includereststrokes']
- waterboattype = options['waterboattype']
- workstrokesonly = not includereststrokes
- theuser = options['theuser']
- xparam = options['xparam']
- yparam1 = options['yparam1']
- yparam2 = options['yparam2']
- startdatestring = options['startdatestring']
- enddatestring = options['enddatestring']
- deltadays = options['deltadays']
- except KeyError:
- modality = def_options['modality']
- rankingonly = def_options['rankingonly']
- includereststrokes = def_options['includereststrokes']
- waterboattype = def_options['waterboattype']
- workstrokesonly = not includereststrokes
- theuser = def_options['theuser']
- xparam = def_options['xparam']
- yparam1 = def_options['yparam1']
- yparam2 = def_options['yparam2']
- startdatestring = def_options['startdatestring']
- enddatestring = def_options['enddatestring']
- deltadays = def_options['deltadays']
- request.session['options'] = def_options
-
+ modality = keyvalue_get_default('modality',options,def_options)
+ rankingonly = keyvalue_get_default('rankingonly',options,def_options)
+ includereststrokes = keyvalue_get_default('includereststrokes',options,def_options)
+ waterboattype = keyvalue_get_default('waterboattype',options,def_options)
+ workstrokesonly = not includereststrokes
+ theuser = keyvalue_get_default('theuser',options,def_options)
+ xparam = keyvalue_get_default('xparam',options,def_options)
+ yparam1 = keyvalue_get_default('yparam1',options,def_options)
+ yparam2 = keyvalue_get_default('yparam2',options,def_options)
+ startdatestring = keyvalue_get_default('startdatestring',options,def_options)
+ enddatestring = keyvalue_get_default('enddatestring',options,def_options)
if modality == 'all':
modalities = [m[0] for m in types.workouttypes]
@@ -2515,9 +2505,6 @@ def cum_flex_data(
except ParseError:
enddate = timezone.now()
- if deltadays>0:
- startdate = enddate-datetime.timedelta(days=int(deltadays))
-
if enddate < startdate:
s = enddate
@@ -2648,10 +2635,10 @@ def cum_flex(request,theuser=0,
# get all indoor rows of in date range
# process form
- if request.method == 'POST' and "daterange" in request.POST:
+ if request.method == 'POST':
form = DateRangeForm(request.POST)
- deltaform = DeltaDaysForm(request.POST)
- optionsform = StatsOptionsForm()
+ modalityform = TrendFlexModalForm(request.POST)
+ flexaxesform = FlexAxesForm(request,request.POST)
if form.is_valid():
startdate = form.cleaned_data['startdate']
enddate = form.cleaned_data['enddate']
@@ -2659,27 +2646,6 @@ def cum_flex(request,theuser=0,
s = enddate
enddate = startdate
startdate = s
- elif request.method == 'POST' and "datedelta" in request.POST:
- deltaform = DeltaDaysForm(request.POST)
- optionsform = TrendFlexModalForm()
- if deltaform.is_valid():
- deltadays = deltaform.cleaned_data['deltadays']
- if deltadays != 0 and isinstance(deltadays, Number):
- enddate = timezone.now()
- startdate = enddate-datetime.timedelta(days=deltadays)
- if startdate > enddate:
- s = enddate
- enddate = startdate
- startdate = s
- form = DateRangeForm(initial={
- 'startdate': startdate,
- 'enddate': enddate,
- })
- else:
- form = DateRangeForm()
- optionsform = TrendFlexModalForm()
- elif request.method == 'POST' and 'options' in request.POST:
- modalityform = TrendFlexModalForm(request.POST)
if modalityform.is_valid():
modality = modalityform.cleaned_data['modality']
waterboattype = modalityform.cleaned_data['waterboattype']
@@ -2700,29 +2666,37 @@ def cum_flex(request,theuser=0,
'startdate': startdate,
'enddate': enddate,
})
- deltaform = DeltaDaysForm()
- else:
- form = DateRangeForm(initial={
- 'startdate': startdate,
- 'enddate': enddate,
- })
- deltaform = DeltaDaysForm()
+ if flexaxesform.is_valid():
+ xparam = flexaxesform.cleaned_data['xaxis']
+ yparam1 = flexaxesform.cleaned_data['yaxis1']
+ yparam2 = flexaxesform.cleaned_data['yaxis2']
else:
form = DateRangeForm(initial={
'startdate': startdate,
'enddate': enddate,
})
- deltaform = DeltaDaysForm()
- modalityform = TrendFlexModalForm()
+ includereststrokes = False
+
+ workstrokesonly = not includereststrokes
+ modalityform = TrendFlexModalForm(
+ initial={
+ 'modality':modality,
+ 'waterboattype':waterboattype,
+ 'rankingonly':rankingonly,
+ }
+ )
+ initial = {
+ 'xaxis':xparam,
+ 'yaxis1':yparam1,
+ 'yaxis2':yparam2
+ }
+ flexaxesform = FlexAxesForm(request,initial=initial)
negtypes = []
for b in types.boattypes:
if b[0] not in waterboattype:
negtypes.append(b[0])
- includereststrokes = False
-
- workstrokesonly = not includereststrokes
script = ''
@@ -2730,21 +2704,8 @@ def cum_flex(request,theuser=0,
js_resources = ''
css_resources = ''
- axchoicesbasic = {ax[0]:ax[1] for ax in axes if ax[4]=='basic'}
- axchoicespro = {ax[0]:ax[1] for ax in axes if ax[4]=='pro'}
- noylist = ["time","distance"]
- axchoicesbasic.pop("cumdist")
-
-
- modalityform = TrendFlexModalForm(
- initial={
- 'modality':modality,
- 'waterboattype':waterboattype,
- 'rankingonly':rankingonly,
- }
- )
+
-
options = {
'xparam': xparam,
@@ -2755,7 +2716,6 @@ def cum_flex(request,theuser=0,
'waterboattype':waterboattype,
'startdatestring':startdatestring,
'enddatestring':enddatestring,
- 'deltadays':deltadays,
'rankingonly':rankingonly,
'includereststrokes':includereststrokes,
}
@@ -2786,15 +2746,12 @@ def cum_flex(request,theuser=0,
'enddate':enddate,
'form':form,
'optionsform':modalityform,
- 'deltaform':deltaform,
'xparam':xparam,
'yparam1':yparam1,
'yparam2':yparam2,
'promember':promember,
'teams':get_my_teams(request.user),
- 'axchoicesbasic':axchoicesbasic,
- 'axchoicespro':axchoicespro,
- 'noylist':noylist,
+ 'flexaxesform':flexaxesform,
})