From 2178a25db35b2b4aa8b4ca2dee578cb2bdfa7c99 Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Sun, 2 Dec 2018 12:26:21 +0100
Subject: [PATCH] added manual and upload links to race page
---
rowers/models.py | 2 +-
rowers/plannedsessions.py | 37 +++++++++++++++++++++++++++++-
rowers/templates/virtualevent.html | 32 +++++++++++++++++++++++++-
rowers/templates/workout_form.html | 10 ++++++++
rowers/views.py | 9 ++++++++
5 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/rowers/models.py b/rowers/models.py
index ce91d5c2..09a61c8b 100644
--- a/rowers/models.py
+++ b/rowers/models.py
@@ -2690,7 +2690,7 @@ class WorkoutForm(ModelForm):
startdate__lte=workout.date,
enddate__gte=workout.date,
).order_by("preferreddate","startdate","enddate").exclude(
- sessiontype='race')
+ sessiontype__in=['race','indoorrace'])
if not sps:
del self.fields['plannedsession']
diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py
index fdef9f08..09c657b4 100644
--- a/rowers/plannedsessions.py
+++ b/rowers/plannedsessions.py
@@ -20,7 +20,7 @@ from rowers.models import (
Rower, Workout,Team,
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
TrainingPlan,PlannedSession,VirtualRaceResult,CourseTestResult,
- get_course_timezone, IndoorVirtualRaceResult
+ get_course_timezone, IndoorVirtualRaceResult,VirtualRace
)
from rowers.courses import get_time_course
@@ -33,6 +33,41 @@ import iso8601
from iso8601 import ParseError
from rowers.tasks import handle_check_race_course
+def get_indoorraces(workout):
+ races1 = VirtualRace.objects.filter(
+ registration_closure__gt=timezone.now(),
+ sessiontype='indoorrace',
+ startdate__lte=workout.date,
+ enddate__gte=workout.date,
+ sessionmode='distance',
+ sessionvalue=workout.distance)
+
+
+ if workout.duration.second != 0 and workout.duration.microsecond != 0:
+ duration = 60*workout.duration.hour+workout.duration.minute
+
+
+ races2 = VirtualRace.objects.filter(
+ registration_closure__gt=timezone.now(),
+ sessiontype='indoorrace',
+ startdate__lte=workout.date,
+ enddate__gte=workout.date,
+ sessionmode='time',
+ sessionvalue=duration)
+
+ races = races1 | races2
+ else:
+ races = races1
+
+ registrations = IndoorVirtualRaceResult.objects.filter(
+ race__in = races,
+ userid=workout.user.id)
+
+ races = [r.race for r in registrations]
+
+
+ return races
+
def get_todays_micro(plan,thedate=date.today()):
thismicro = None
diff --git a/rowers/templates/virtualevent.html b/rowers/templates/virtualevent.html
index 7271460e..cf192349 100644
--- a/rowers/templates/virtualevent.html
+++ b/rowers/templates/virtualevent.html
@@ -155,7 +155,37 @@ data-text="@rowsandall #rowingdata Participate in Indoor Rowing virtual race '{{
{% endif %}
{% if button == 'submitbutton' %}
- Submit Result
+
+
+ |
+ Submit Workout
+ |
+
+ Submit a workout that is already on the site as your race result
+ |
+
+
+ |
+ Upload your race result
+ |
+
+ Upload a new workout to the site and submit it as a result. You
+ need a workout data file.
+ |
+
+ {% if race.sessiontype == 'indoorrace' %}
+
+ |
+ Enter your race result manually
+ |
+
+ If you don't have a data file, enter the results
+ manually. If you have a photo of the monitor with the
+ result, it is recommended to add this to the workout.
+ |
+
+ {% endif %}
+
{% endif %}
{% if button == 'resubmitbutton' %}
diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html
index ce0e29e6..986878ec 100644
--- a/rowers/templates/workout_form.html
+++ b/rowers/templates/workout_form.html
@@ -118,6 +118,16 @@ $('#id_workouttype').change();
+ {% if indoorraces %}
+
+ Racing
+ {% for race in indoorraces %}
+
+ Submit this to Indoor Race {{ race.name }}
+
+ {% endfor %}
+
+ {% endif %}
{% if mapdiv %}
diff --git a/rowers/views.py b/rowers/views.py
index f8576213..825c1015 100644
--- a/rowers/views.py
+++ b/rowers/views.py
@@ -3460,6 +3460,12 @@ def addmanual_view(request):
add_workouts_plannedsession([w],ps,w.user)
messages.info(request,'New workout created')
+
+ url = reverse(
+ workout_edit_view,
+ kwargs={'id':id}
+ )
+ return HttpResponseRedirect(url)
else:
return render(request,'manualadd.html',
{'form':form,
@@ -9979,6 +9985,8 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
row = get_workout(id)
+ indoorraces = get_indoorraces(row)
+
if (checkworkoutuser(request.user,row)==False):
raise PermissionDenied("Access denied")
@@ -10171,6 +10179,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
'graphs':g,
'breadcrumbs':breadcrumbs,
'rower':r,
+ 'indoorraces':indoorraces,
'active':'nav-workouts',
'mapscript':mapscript,
'mapdiv':mapdiv,