From c74b08d9662861b70bef631ec71a68a96c027e7d Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 10 Aug 2017 13:58:47 +0200 Subject: [PATCH] modality and boat type selection working on multiflex --- rowers/admin.py | 2 +- rowers/forms.py | 6 ++- rowers/models.py | 33 ++++++++---- rowers/templates/user_multiflex_select.html | 51 +++++++++++++++++- rowers/views.py | 58 +++++++++++++++++++-- 5 files changed, 132 insertions(+), 18 deletions(-) diff --git a/rowers/admin.py b/rowers/admin.py index ea7a79ce..1cbc67be 100644 --- a/rowers/admin.py +++ b/rowers/admin.py @@ -21,7 +21,7 @@ class UserAdmin(UserAdmin): inlines = (RowerInline,) class WorkoutAdmin(admin.ModelAdmin): - list_display = ('date','user','name','workouttype') + list_display = ('date','user','name','workouttype','boattype') class FavoriteChartAdmin(admin.ModelAdmin): list_display = ('user','xparam','yparam1','yparam2','plottype','workouttype','reststrokes') diff --git a/rowers/forms.py b/rowers/forms.py index 910b6ce5..732097e4 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -265,11 +265,15 @@ class IntervalUpdateForm(forms.Form): boattypes = types.boattypes workouttypes = types.workouttypes +ww = list(workouttypes) +ww.append(tuple(('all','All'))) +workouttypes = tuple(ww) # form to select modality and boat type for trend flex class TrendFlexModalForm(forms.Form): modality = forms.ChoiceField(choices=workouttypes, - label='Workout Type') + label='Workout Type', + initial='all') waterboattype = forms.MultipleChoiceField(choices=boattypes, label='Water Boat Type', initial = ['1x','2x','2-','4x','4-','8+']) diff --git a/rowers/models.py b/rowers/models.py index 011eb585..371331f5 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -368,7 +368,7 @@ class Workout(models.Model): workoutsource = models.CharField(choices=workoutsources,max_length=100, default='unknown') boattype = models.CharField(choices=boattypes,max_length=50, - default='1x (single)', + default='1x', verbose_name = 'Boat Type') starttime = models.TimeField(blank=True,null=True) startdatetime = models.DateTimeField(blank=True,null=True) @@ -405,17 +405,30 @@ class Workout(models.Model): ownerfirst = self.user.user.first_name ownerlast = self.user.user.last_name duration = self.duration + boattype = self.boattype workouttype = self.workouttype - stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {workouttype} {ownerfirst} {ownerlast}'.format( - d = date.strftime('%Y-%m-%d'), - n = name, - dist = distance, - duration = duration, - workouttype = workouttype, - ownerfirst = ownerfirst, - ownerlast = ownerlast, - ) + if workouttype != 'water': + stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {workouttype} {ownerfirst} {ownerlast}'.format( + d = date.strftime('%Y-%m-%d'), + n = name, + dist = distance, + duration = duration, + workouttype = workouttype, + ownerfirst = ownerfirst, + ownerlast = ownerlast, + ) + else: + stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {workouttype} {boattype} {ownerfirst} {ownerlast}'.format( + d = date.strftime('%Y-%m-%d'), + n = name, + dist = distance, + duration = duration, + workouttype = workouttype, + boattype=boattype, + ownerfirst = ownerfirst, + ownerlast = ownerlast, + ) return stri diff --git a/rowers/templates/user_multiflex_select.html b/rowers/templates/user_multiflex_select.html index 06db28ce..11fb6e4d 100644 --- a/rowers/templates/user_multiflex_select.html +++ b/rowers/templates/user_multiflex_select.html @@ -12,6 +12,55 @@ checkboxes[i].checked = source.checked; } } + + + @@ -75,7 +124,7 @@ {% csrf_token %}
- +
diff --git a/rowers/views.py b/rowers/views.py index 6dd967da..a3863a47 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -98,7 +98,7 @@ from scipy.signal import savgol_filter from django.shortcuts import render_to_response from Cookie import SimpleCookie from shutil import copyfile - +import types from rowingdata import rower as rrower from rowingdata import main as rmain from rowingdata import rowingdata as rrdata @@ -3375,6 +3375,7 @@ def user_multiflex_select(request, except: ploterrorbars = False + if 'startdate' in request.session: startdate = iso8601.parse_date(request.session['startdate']) @@ -3384,17 +3385,55 @@ def user_multiflex_select(request, enddate = iso8601.parse_date(request.session['enddate']) - if request.method == 'POST': + if 'waterboattype' in request.session: + waterboattype = request.session['waterboattype'] + else: + waterboattype = ['1x','2x','2-','4x','4-','8+'] + + + 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] + + if request.method == 'POST' and 'daterange' in request.POST: dateform = DateRangeForm(request.POST) if dateform.is_valid(): startdate = dateform.cleaned_data['startdate'] enddate = dateform.cleaned_data['enddate'] + startdatestring = startdate.strftime('%Y-%m-%d') + enddatestring = enddate.strftime('%Y-%m-%d') + request.session['startdate'] = startdatestring + request.session['enddate'] = enddatestring + print 'nootje',enddatestring,request.session['enddate'] else: dateform = DateRangeForm(initial={ 'startdate':startdate, '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 modality != 'water': + waterboattype = [b[0] for b in types.boattypes] + + + 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)) enddate = enddate+datetime.timedelta(days=1) @@ -3410,9 +3449,15 @@ def user_multiflex_select(request, startdate = s + negtypes = [] + for b in types.boattypes: + if b[0] not in waterboattype: + negtypes.append(b[0]) + workouts = Workout.objects.filter(user=r, startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by("-date", "-starttime") + startdatetime__lte=enddate, + workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes) query = request.GET.get('q') if query: @@ -3433,7 +3478,10 @@ def user_multiflex_select(request, 'includereststrokes':includereststrokes, }) - modalityform = TrendFlexModalForm() + modalityform = TrendFlexModalForm(initial={ + 'modality':modality, + 'waterboattype':waterboattype + }) messages.info(request,successmessage) messages.error(request,message) @@ -3702,7 +3750,7 @@ def multiflex_view(request,userid=0, clegendy = df['groupval'].min()+clegendx*(df['groupval'].max()-df['groupval'].min()) else: clegendy = df.index.min()+clegendx*(df.index.max()-df.index.min()) - print clegendy + colorlegend = zip(range(6),clegendy,legcolors)