From 06ecf74cb547eeccfb05f3b0887a1ba2e612d295 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 13 Apr 2018 08:16:46 +0200 Subject: [PATCH] forbidden saving ad hoc metrics as favorite chart --- rowers/interactiveplots.py | 7 +++++-- rowers/views.py | 13 +++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 90d0ee2a..dd0fa820 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -3468,8 +3468,11 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, plot.yaxis.axis_label = 'Y' - - yrange1 = Range1d(start=yaxminima[yparam1],end=yaxmaxima[yparam1]) + try: + yrange1 = Range1d(start=yaxminima[yparam1],end=yaxmaxima[yparam1]) + except KeyError: + yrange1 = Range1d(start=yparam1.min(), end=yparam1.max()) + plot.y_range = yrange1 if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): diff --git a/rowers/views.py b/rowers/views.py index 69a9a60f..58fd0d60 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -8413,11 +8413,20 @@ def workout_flexchart3_view(request,*args,**kwargs): workstrokesonly = request.POST['workstrokesonlysave'] reststrokes = not workstrokesonly r = getrower(request.user) - f = FavoriteChart(user=r,xparam=xparam, + try: + r = metrics.yaxmaxima[xparam] + if yparam1 is not None: + r = metrics.yaxmaxima[yparam1] + if yparam2 is not None: + r = metrics.yaxmaxima[yparam2] + f = FavoriteChart(user=r,xparam=xparam, yparam1=yparam1,yparam2=yparam2, plottype=plottype,workouttype=workouttype, reststrokes=reststrokes) - f.save() + f.save() + + except KeyError: + messages.error(request,'We cannot save the ad hoc metrics in a favorite chart') if request.method == 'POST' and 'workstrokesonly' in request.POST: workstrokesonly = request.POST['workstrokesonly']