Private
Public Access
1
0

using sessions to keep workout type selected

This commit is contained in:
Sander Roosendaal
2017-02-07 15:54:07 +01:00
parent 2fc2431de9
commit abcf2f1789
3 changed files with 123 additions and 60 deletions

View File

@@ -20,9 +20,13 @@ from django.conf import settings
from django.utils.datastructures import MultiValueDictKeyError
from django.utils import timezone,translation
from django.core.mail import send_mail, BadHeaderError
from rowers.forms import EmailForm, RegistrationForm, RegistrationFormTermsOfService,RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,UpdateStreamForm
from rowers.forms import PredictedPieceForm,DateRangeForm,DeltaDaysForm
from rowers.forms import SummaryStringForm,IntervalUpdateForm,StrokeDataForm
from rowers.forms import (
SummaryStringForm,IntervalUpdateForm,StrokeDataForm,
StatsOptionsForm,PredictedPieceForm,DateRangeForm,DeltaDaysForm,
EmailForm, RegistrationForm, RegistrationFormTermsOfService,
RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,
UpdateStreamForm
)
from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart
from rowers.models import (
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
@@ -55,7 +59,7 @@ from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
from rowers.tasks import handle_sendemail_unrecognized
from scipy.signal import savgol_filter
from django.shortcuts import render_to_response
from Cookie import SimpleCookie
from shutil import copyfile
from rowingdata import rower as rrower
@@ -2616,12 +2620,20 @@ def cumstats(request,theuser=0,
enddate=timezone.now(),
deltadays=-1,
startdatestring="",
enddatestring="",
workstrokesonly=True):
workstrokesonly = True
if request.method == 'POST' and 'workstrokesonly' in request.POST:
enddatestring="",
options={
'includereststrokes':False,
'workouttypes':['rower','dynamic','slides']
}):
if 'options' in request.session:
options = request.session['options']
workouttypes = options['workouttypes']
includereststrokes = options['includereststrokes']
workstrokesonly = not includereststrokes
checktypes = ['water','rower','dynamic','slides','skierg',
'paddle','snow','other']
if deltadays>0:
startdate = enddate-datetime.timedelta(days=int(deltadays))
@@ -2654,6 +2666,7 @@ def cumstats(request,theuser=0,
# process form
if request.method == 'POST' and "daterange" in request.POST:
form = DateRangeForm(request.POST)
deltaform = DeltaDaysForm(request.POST)
optionsform = StatsOptionsForm()
if form.is_valid():
startdate = form.cleaned_data['startdate']
@@ -2676,20 +2689,41 @@ def cumstats(request,theuser=0,
form = DateRangeForm(initial={
'startdate': startdate,
'enddate': enddate,
})
optionsform = StatsOptionsForm()
else:
form = DateRangeForm()
optionsform = StatsOptionsForm()
elif request.method == 'POST' and 'options' in request.POST:
optionsform = StatsOptionsForm(request.POST)
if optionsform.is_valid():
includereststrokes = optionsform.cleaned_data['includereststrokes']
workstrokesonly = not includereststrokes
workouttypes = []
for type in checktypes:
if optionsform.cleaned_data[type]:
workouttypes.append(type)
options = {
'includereststrokes':includereststrokes,
'workouttypes':workouttypes,
}
form = DateRangeForm()
deltaform = DeltaDaysForm()
else:
form = DateRangeForm()
deltaform = DeltaDaysForm()
else:
form = DateRangeForm(initial={
'startdate': startdate,
'enddate': enddate,
})
deltaform = DeltaDaysForm()
optionsform = StatsOptionsForm()
try:
r2 = Rower.objects.get(user=theuser)
allergworkouts = Workout.objects.filter(user=r2,
allergworkouts = Workout.objects.filter(user=r2,
workouttype__in=workouttypes,
startdatetime__gte=startdate,
startdatetime__lte=enddate)
@@ -2795,7 +2829,6 @@ def cumstats(request,theuser=0,
try:
datadf = datadf[~datadf['workoutstate'].isin(workoutstatesrest)]
except:
pass
pass
# Create stats
@@ -2828,20 +2861,38 @@ def cumstats(request,theuser=0,
thedict[field2] = 0
cordict[field1] = thedict
# set options form correctly
initial = {}
initial['includereststrokes'] = includereststrokes
for wtype in checktypes:
if wtype in workouttypes:
initial[wtype] = True
else:
initial[wtype] = False
optionsform = StatsOptionsForm(initial=initial)
response = render(request,
'cumstats.html',
{
'stats':stats,
'stats':stats,
'options':options,
'id':theuser,
'theuser':u,
'startdate':startdate,
'enddate':enddate,
'form':form,
'deltaform':deltaform,
'optionsform':optionsform,
'cordict':cordict,
})
request.session['options'] = options
return response
# Stats page
@login_required()