From a226a957c8f2cd3b71fa3366c08f95d05433f64a Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 12 Oct 2017 10:02:50 +0200 Subject: [PATCH] implemented default set of flex favs on user registration --- rowers/metrics.py | 59 ++++++++++++++++++++++++++++- rowers/models.py | 2 + rowers/templates/flexchart3.html | 2 - rowers/templates/flexchart3otw.html | 2 - rowers/views.py | 23 ++++++++++- 5 files changed, 81 insertions(+), 7 deletions(-) diff --git a/rowers/metrics.py b/rowers/metrics.py index b4140f1c..27694003 100644 --- a/rowers/metrics.py +++ b/rowers/metrics.py @@ -219,7 +219,7 @@ rowingmetrics = ( 'ax_max': 15, 'default': 0, 'mode':'both', - 'type': 'pro'}), + 'type': 'basic'}), ) @@ -236,3 +236,60 @@ axlabels = {ax[0]:ax[1] for ax in axes} yaxminima = {ax[0]:ax[2] for ax in axes} yaxmaxima = {ax[0]:ax[3] for ax in axes} + +defaultfavoritecharts = ( + { + 'yparam1':'pace', + 'yparam2':'spm', + 'xparam':'time', + 'plottype':'line', + 'workouttype':'both', + 'reststrokes':True, + 'notes':'Some Notes 1', + }, + { + 'yparam1':'pace', + 'yparam2':'hr', + 'xparam':'time', + 'plottype':'line', + 'workouttype':'both', + 'reststrokes':True, + 'notes':'Some Notes 2', + }, + { + 'yparam1':'distanceperstroke', + 'yparam2':'hr', + 'xparam':'time', + 'plottype':'line', + 'workouttype':'otw', + 'reststrokes':True, + 'notes':'Some Notes 3', + }, + { + 'yparam1':'strokeenergy', + 'yparam2':'hr', + 'xparam':'time', + 'plottype':'line', + 'workouttype':'ote', + 'reststrokes':True, + 'notes':'Some Notes 3', + }, + { + 'yparam1':'distanceperstroke', + 'yparam2':'None', + 'xparam':'spm', + 'plottype':'line', + 'workouttype':'otw', + 'reststrokes':True, + 'notes':'Some Notes 4', + }, + { + 'yparam1':'strokeenergy', + 'yparam2':'None', + 'xparam':'spm', + 'plottype':'line', + 'workouttype':'ote', + 'reststrokes':True, + 'notes':'Some Notes 4', + }, + ) diff --git a/rowers/models.py b/rowers/models.py index 6bb2c91e..2913c6be 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -344,6 +344,8 @@ class FavoriteChart(models.Model): default='both', verbose_name='Workout Type') reststrokes = models.BooleanField(default=True,verbose_name="Incl. Rest") + notes = models.CharField(max_length=300,verbose_name='Chart Notes', + default='Flex Chart Notes',blank=True) user = models.ForeignKey(Rower) diff --git a/rowers/templates/flexchart3.html b/rowers/templates/flexchart3.html index aa49ff65..37aaac5c 100644 --- a/rowers/templates/flexchart3.html +++ b/rowers/templates/flexchart3.html @@ -168,7 +168,6 @@ -{% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %}
{% if maxfav >= 0 %} @@ -204,7 +203,6 @@ {% endif %}
-{% endif %} {% endblock %} {% endlocaltime %} diff --git a/rowers/templates/flexchart3otw.html b/rowers/templates/flexchart3otw.html index 52a8eeaa..5da6e48c 100644 --- a/rowers/templates/flexchart3otw.html +++ b/rowers/templates/flexchart3otw.html @@ -151,7 +151,6 @@ -{% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %}
{% if maxfav >= 0 %} @@ -187,7 +186,6 @@ {% endif %}
-{% endif %} {% endblock %} {% endlocaltime %} diff --git a/rowers/views.py b/rowers/views.py index 074b5b65..03f119a3 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -49,7 +49,7 @@ from rowers.models import ( WorkoutComment,WorkoutCommentForm,RowerExportForm, ) from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement -from rowers.metrics import rowingmetrics +from rowers.metrics import rowingmetrics,defaultfavoritecharts import rowers.uploads as uploads from django.forms.formsets import formset_factory import StringIO @@ -324,6 +324,22 @@ def ispromember(user): result = False return result +# More User/Rower utils +def add_defaultfavorites(r): + for c in defaultfavoritecharts: + f = FavoriteChart(user=r, + yparam1=c['yparam1'], + yparam2=c['yparam2'], + xparam=c['xparam'], + plottype=c['plottype'], + workouttype=c['workouttype'], + reststrokes=c['reststrokes'], + notes=c['notes']) + + f.save() + return 1 + + # User registration def rower_register_view(request): if request.method == 'POST': @@ -344,6 +360,9 @@ def rower_register_view(request): therower.save() + # create default favorite charts + add_defaultfavorites(therower) + # Create Sample workout f = 'media/testdata.csv.gz' timestr = strftime("%Y%m%d-%H%M%S") @@ -8258,7 +8277,7 @@ def workout_summary_edit_view(request,id,message="",successmessage="" }) # Page where user can manage his favorite charts -@user_passes_test(ispromember,login_url="/rowers/me/edit",redirect_field_name=None) +@login_required() def rower_favoritecharts_view(request): message = '' successmessage = ''