From f3ddad40bcaefc49a9f5e53690058d7112258b7e Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 25 Oct 2018 09:35:13 +0200 Subject: [PATCH] fixing date selector bug --- rowers/views.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/rowers/views.py b/rowers/views.py index a6871032..41372305 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -2526,6 +2526,7 @@ def rower_process_testcallback(request): def keyvalue_get_default(key,options,def_options): + try: return options[key] except KeyError: @@ -2544,17 +2545,17 @@ def cum_flex_data( 'xparam':'spm', 'yparam1':'power', 'yparam2':'None', - 'enddatestring':'', - 'startdatestring':'', + 'enddatestring':timezone.now().strftime("%Y-%m-%d"), + 'startdatestring':(timezone.now()-datetime.timedelta(days=30)).strftime("%Y-%m-%d"), 'deltadays':-1, }): def_options = options - if 'options' in request.session: options = request.session['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) @@ -2567,6 +2568,7 @@ def cum_flex_data( 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 mytypes.workouttypes] else: @@ -2604,7 +2606,7 @@ def cum_flex_data( rankingpiece = [True,] else: rankingpiece = [True,False] - + allworkouts = Workout.objects.filter(user=r2, workouttype__in=modalities, boattype__in=waterboattype, @@ -2645,8 +2647,8 @@ def histo_data( 'modality':'all', 'waterboattype':mytypes.waterboattype, 'theuser':0, - 'enddatestring':'', - 'startdatestring':'', + 'enddatestring':timezone.now().strftime("%Y-%m-%d"), + 'startdatestring':(timezone.now()-datetime.timedelta(days=30)).strftime("%Y-%m-%d"), 'deltadays':-1, }): @@ -2739,8 +2741,8 @@ def cum_flex(request,theuser=0, startdate=timezone.now()-datetime.timedelta(days=10), enddate=timezone.now(), deltadays=-1, - startdatestring="", - enddatestring="", + enddatestring=timezone.now().strftime("%Y-%m-%d"), + startdatestring=(timezone.now()-datetime.timedelta(days=30)).strftime("%Y-%m-%d"), options={ 'includereststrokes':False, 'workouttypes':[i[0] for i in mytypes.workouttypes], @@ -2816,6 +2818,8 @@ def cum_flex(request,theuser=0, s = enddate enddate = startdate startdate = s + startdatestring = startdate.strftime('%Y-%m-%d') + enddatestring = enddate.strftime('%Y-%m-%d') if modalityform.is_valid(): modality = modalityform.cleaned_data['modality'] waterboattype = modalityform.cleaned_data['waterboattype'] @@ -3112,14 +3116,14 @@ def histo(request,theuser=0, startdate=timezone.now()-datetime.timedelta(days=365), enddate=timezone.now(), deltadays=-1, - startdatestring="", - enddatestring="", - options={ - 'includereststrokes':False, - 'workouttypes':[i[0] for i in mytypes.workouttypes], - 'waterboattype':mytypes.waterboattype, - 'rankingonly': False, - }): + enddatestring=timezone.now().strftime("%Y-%m-%d"), + startdatestring=(timezone.now()-datetime.timedelta(days=30)).strftime("%Y-%m-%d"), + options={ + 'includereststrokes':False, + 'workouttypes':[i[0] for i in mytypes.workouttypes], + 'waterboattype':mytypes.waterboattype, + 'rankingonly': False, + }): r = getrequestrower(request,userid=theuser) theuser = r.user @@ -3187,6 +3191,8 @@ def histo(request,theuser=0, s = enddate enddate = startdate startdate = s + startdatestring = startdate.strftime('%Y-%m-%d') + enddatestring = enddate.strftime('%Y-%m-%d') if modalityform.is_valid(): modality = modalityform.cleaned_data['modality'] waterboattype = modalityform.cleaned_data['waterboattype']