From e0bc7f2b67fb2b6ac04ea99bd55c2b133f71730b Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 7 Oct 2021 07:30:37 +0200 Subject: [PATCH] bug fix fastest distance race --- rowers/plannedsessions.py | 23 ++++++++++++++++++++++- rowers/templates/analysis.html | 2 +- rowers/templates/race_submit.html | 8 ++++---- rowers/templates/virtualevent.html | 8 ++++++++ rowers/views/racesviews.py | 7 ++++++- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 0edb75eb..14efce52 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -1142,6 +1142,12 @@ def update_indoorvirtualrace(ps,cd): ps.timezone = timezone_str + if ps.sessiontype == 'fastest_distance': + ps.approximate_distance = ps.sessionvalue + + if ps.course is not None: + ps.approximate_distance = ps.course.distance + ps.save() return 1,'Virtual Race Updated' @@ -1195,6 +1201,12 @@ def update_virtualrace(ps,cd): ps.timezone = timezone_str + if ps.sessiontype == 'fastest_distance': + ps.approximate_distance = ps.sessionvalue + + if ps.course is not None: + ps.approximate_distance = ps.course.distance + ps.save() return 1,'Virtual Race Updated' @@ -1685,6 +1697,7 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False): ids = [w.id for w in ws] ids = list(set(ids)) + if len(ids)>1 and race.sessiontype in ['test','coursetest','race','indoorrace','fastest_time','fastest_distance']: # pragma: no cover errors.append('For tests, you can only attach one workout') return result,comments,errors,0 @@ -1725,10 +1738,12 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False): errors.append("Couldn't find this entry") return result,comments,errors,0 + + records = IndoorVirtualRaceResult.objects.filter( userid=r.id, race=race, - workoutid = ws[0].id + #workoutid = ws[0].id ) if ws[0].workouttype != record.boatclass: # pragma: no cover @@ -1757,8 +1772,14 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False): errors.append('Workout %i did not match the race window' % ws[0].id) return result,comments,errors,0 + if result>0: for otherrecord in records: # pragma: no cover + oldworkouts = Workout.objects.filter(plannedsession=race) + for oldworkout in oldworkouts: + oldworkout.plannedsession = None + oldworkout.save() + otherrecord.workoutid = None otherrecord.coursecompleted = False otherrecord.save() diff --git a/rowers/templates/analysis.html b/rowers/templates/analysis.html index d19304a9..b1e8ea47 100644 --- a/rowers/templates/analysis.html +++ b/rowers/templates/analysis.html @@ -82,7 +82,7 @@

- BETA: Box Chart Statistics of stroke metrics over a date range + Box Chart Statistics of stroke metrics over a date range

  • diff --git a/rowers/templates/race_submit.html b/rowers/templates/race_submit.html index 4eedefa6..8e8fd16b 100644 --- a/rowers/templates/race_submit.html +++ b/rowers/templates/race_submit.html @@ -24,6 +24,10 @@

    Select one of the following workouts that you rowed within the challenge window

    +

    + {% csrf_token %} + +

    {% for field in w_form.hidden_fields %} @@ -37,10 +41,6 @@ {% endfor %}
    -

    - {% csrf_token %} - -

  • diff --git a/rowers/templates/virtualevent.html b/rowers/templates/virtualevent.html index 40543d22..e47a5f9e 100644 --- a/rowers/templates/virtualevent.html +++ b/rowers/templates/virtualevent.html @@ -255,7 +255,15 @@ {{ result.points|sigdig:4 }} {% endif %} + {% if race.sessiontype == 'race' %} + {% elif race.sessiontype == 'fastest_time' %} + + {% elif race.sessiontype == 'fastest_distance' %} + + {% else %} + + {% endif %} diff --git a/rowers/views/racesviews.py b/rowers/views/racesviews.py index 66db3f8e..7d73abca 100644 --- a/rowers/views/racesviews.py +++ b/rowers/views/racesviews.py @@ -2775,6 +2775,11 @@ def fastestvirtualevent_create_view(request): vs.save() + if vs.sessiontype == 'fastest_distance': + vs.approximate_distance = vs.sessionvalue + + vs.save() + # create Site Announcement & Tweet if settings.DEBUG or settings.TESTING: dotweet = False @@ -3000,7 +3005,6 @@ def virtualevent_edit_view(request,id=0): racecreateform = VirtualRaceForm(request.POST,instance=race) if racecreateform.is_valid(): cd = racecreateform.cleaned_data - res, message = update_virtualrace(race,cd) if res: @@ -3253,6 +3257,7 @@ def virtualevent_submit_result_view(request,id=0,workoutid=0): #workouttype__in=mytypes.rowtypes, startdatetime__gte=startdatetime, startdatetime__lte=enddatetime, + distance__gte=race.approximate_distance, ).order_by("-date","-startdatetime","id") if not ws: # pragma: no cover