From 2a0b0dd7bfe7cfe2aeeef50696cd182510d9d382 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 29 Apr 2020 20:56:00 +0200 Subject: [PATCH] Solves #536 Image upload possible directly in Manual --- rowers/templates/manualadd.html | 14 +++++++++----- rowers/views/workoutviews.py | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/rowers/templates/manualadd.html b/rowers/templates/manualadd.html index a70040c1..b93dba6a 100644 --- a/rowers/templates/manualadd.html +++ b/rowers/templates/manualadd.html @@ -22,12 +22,12 @@ $( document ).ready(function() { || $(this).val() == 'churchboat' ) { $('#id_boattype').toggle(true); - } else { + } else { $('#id_boattype').toggle(false); - $('#id_boattype').val('1x'); + $('#id_boattype').val('1x'); } }); -$('#id_workouttype').change(); +$('#id_workouttype').change(); }); {% endblock %} @@ -41,13 +41,17 @@ $('#id_workouttype').change(); Please correct the error{{ form.errors|pluralize }} below.

{% endif %} - +
{{ form.as_table }} {{ metricsform.as_table }}
+ Optional, add image (PM screenshot): + + {{ iform.as_table }} +
{% csrf_token %}

@@ -56,7 +60,7 @@ $('#id_workouttype').change(); - + {% endblock %} diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 2e4817a3..bb192e93 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -665,6 +665,25 @@ def addmanual_view(request,raceid=0): messages.info(request,'New workout created') + iform = ImageForm(request.POST,request.FILES) + if iform.is_valid(): + f = iform.cleaned_data['file'] + + if f is not None: + filename,path_and_filename = handle_uploaded_image(f) + try: + width, height = Image.open(path_and_filename).size + except: + message = "Not a valid image" + messages.error(request,message) + os.remove(path_and_filename) + + i = GraphImage(workout=w, + creationdatetime=timezone.now(), + filename = path_and_filename, + width=width,height=height) + i.save() + if raceid != 0: try: race = VirtualRace.objects.get(id=raceid) @@ -727,6 +746,7 @@ def addmanual_view(request,raceid=0): else: return render(request,'manualadd.html', {'form':form, + 'iform':iform, 'metricsform':metricsform, 'breadcrumbs':breadcrumbs, 'active':'nav-workouts', @@ -742,10 +762,12 @@ def addmanual_view(request,raceid=0): } form = WorkoutForm(initial=initial) + iform = ImageForm() metricsform = MetricsForm() return render(request,'manualadd.html', {'form':form, + 'iform':iform, 'metricsform':metricsform, 'breadcrumbs':breadcrumbs, 'active':'nav-workouts',