From 8de1d4465fba1f25ea9655c74ffc592075c59d6d Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 6 Apr 2018 23:47:30 +0200 Subject: [PATCH] new interval parser --- rowers/templates/summary_edit.html | 2 +- rowers/views.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rowers/templates/summary_edit.html b/rowers/templates/summary_edit.html index 93e1d89a..08322e00 100644 --- a/rowers/templates/summary_edit.html +++ b/rowers/templates/summary_edit.html @@ -83,7 +83,7 @@ 8 times 500m with 3 minutes 30 seconds rest -4x(500m+500m)/5min4 times 1km, but each km is reported as two 500m intervals without rest +4x((500m+500m)/5min)4 times 1km, but each km is reported as two 500m intervals without rest. Note the nested parentheses. 2x500m/500mA 2k rowed as 500m "on", 500m "off" diff --git a/rowers/views.py b/rowers/views.py index 3805e49a..3143e41a 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -19,6 +19,7 @@ from django.db import IntegrityError, transaction from django.views.decorators.csrf import csrf_exempt from matplotlib.backends.backend_agg import FigureCanvas import gc +from pyparsing import ParseException from django.shortcuts import render from django.http import ( @@ -10926,8 +10927,8 @@ def workout_summary_edit_view(request,id,message="",successmessage="" s = cd["intervalstring"] try: rowdata.updateinterval_string(s) - except IndexError: - messages.error(request,'Interval string parse error') + except ParseException,err: + messages.error(request,'Parsing error in column '+str(err.col)) intervalstats = rowdata.allstats() itime,idist,itype = rowdata.intervalstats_values() nrintervals = len(idist) @@ -10936,7 +10937,11 @@ def workout_summary_edit_view(request,id,message="",successmessage="" # we are saving the results obtained from the mini language interpreter elif request.method == 'POST' and "savestringform" in request.POST: s = request.POST["savestringform"] - rowdata.updateinterval_string(s) + try: + rowdata.updateinterval_string(s) + except ParseException,err: + messages.error(request,'Parsing error in column '+str(err.col)) + intervalstats = rowdata.allstats() itime,idist,itype = rowdata.intervalstats_values() nrintervals = len(idist)