Private
Public Access
1
0

passing tests

This commit is contained in:
Sander Roosendaal
2022-10-07 15:43:13 +02:00
parent 1e5b6f6cd8
commit e6160ae82e
6 changed files with 87 additions and 41 deletions

View File

@@ -2916,10 +2916,12 @@ def instroke_chart(request, id=0, metric=''): # pragma: no cover
return HttpResponseRedirect(url)
@permission_required('workout.change_workout', fn=get_workout_by_opaqueid, raise_exception=True)
def instroke_chart_interactive(request, id=0):
def instroke_chart_interactive(request, id=0, analysis=0, userid=0):
is_ajax = request_is_ajax(request)
r = getrequestrower(request, userid=userid)
w = get_workoutuser(id, request)
rowdata = rrdata(csvfile=w.csvfilename)
@@ -2975,19 +2977,64 @@ def instroke_chart_interactive(request, id=0):
'maxminutes': maxminutes,
})
if analysis:
try:
instroke_analysis = InStrokeAnalysis.objects.get(id=analysis)
if instroke_analysis.rower != r:
analysis = 0
messages.error(request,'Access to this saved analysis denied')
raise ValueError
if instroke_analysis.workout != w:
messages.error(request,'This saved analysis belongs to a different workout')
form = InstrokeForm(
choices=instrokemetrics,
initial={
'metric':instroke_analysis.metric,
'name': instroke_analysis.name,
'notes': instroke_analysis.notes,
'activeminutesmin':int(instroke_analysis.start_second/60.),
'activeminutesmax':int(instroke_analysis.end_second/60.),
'spm_min': instroke_analysis.spm_min,
'spm_max': instroke_analysis.spm_max,
}
)
metric = instroke_analysis.metric
name = instroke_analysis.name
notes = instroke_analysis.notes
activeminutesmin = int(instroke_analysis.start_second/60.)
activeminutesmax = int(instroke_analysis.end_second/60.)
spm_min = instroke_analysis.spm_min
spm_max = instroke_analysis.spm_max
except (InStrokeAnalysis.DoesNotExist, ValueError):
metric = instrokemetrics[0]
spm_min = 15
spm_max = 45
name = ''
notes = ''
activeminutesmax = int(rowdata.duration/60.)
activeminutesmin = 0
else:
metric = instrokemetrics[0]
spm_min = 15
spm_max = 45
name = ''
notes = ''
activeminutesmax = int(rowdata.duration/60.)
activeminutesmin = 0
maxminutes = int(rowdata.duration/60.)
individual_curves = False
script = ''
div = get_call()
metric = instrokemetrics[0]
spm_min = 15
spm_max = 45
name = ''
notes = ''
activeminutesmax = int(rowdata.duration/60.)
activeminutesmin = 0
maxminutes = activeminutesmax
individual_curves = False
if request.method == 'POST':
form = InstrokeForm(request.POST,choices=instrokemetrics)
@@ -3002,18 +3049,31 @@ def instroke_chart_interactive(request, id=0):
name = form.cleaned_data['name']
if "_save" in request.POST:
instroke_analysis = InStrokeAnalysis(
workout = w,
metric = metric,
name = name,
date = timezone.now().date(),
notes = notes,
start_second = 60*activeminutesmin,
end_second = 60*activeminutesmax,
spm_min = spm_min,
spm_max = spm_max,
rower=w.user,
)
if not analysis:
instroke_analysis = InStrokeAnalysis(
workout = w,
metric = metric,
name = name,
date = timezone.now().date(),
notes = notes,
start_second = 60*activeminutesmin,
end_second = 60*activeminutesmax,
spm_min = spm_min,
spm_max = spm_max,
rower=w.user,
)
else:
instroke_analysis.workout = w
instroke_analysis.metric = metric
instroke_analysis.name = name
instroke_analysis.date = timezone.now().date()
instroke_analysis.notes = notes
instroke_analysis.start_second = 60*activeminutesmin
instroke_analysis.end_second = 60*activeminutesmax
instroke_analysis.spm_min = spm_min
instroke_analysis.spm_max = spm_max
instroke_analysis.rower=w.user
instroke_analysis.save()
messages.info(request,'In-Stroke Analysis saved')