From 283c7cb996e1b6402ac6e9e4ac5f2088df044132 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 13 Oct 2021 21:24:56 +0200 Subject: [PATCH 1/5] expansion to workout_course page --- rowers/templates/menu_workout.html | 12 ++++ rowers/templates/workout_courses.html | 79 +++++++++++++++++++++++++++ rowers/urls.py | 2 + rowers/views/workoutviews.py | 48 ++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 rowers/templates/workout_courses.html diff --git a/rowers/templates/menu_workout.html b/rowers/templates/menu_workout.html index 1a10cc85..b46f79c2 100644 --- a/rowers/templates/menu_workout.html +++ b/rowers/templates/menu_workout.html @@ -26,6 +26,18 @@  Intervals + {% if workout|water %} +
  • + +  Measured Courses + +
  • + {% endif %} +
  • + +  Intervals + +
  • {% endif %} {% if user.is_authenticated %}
  • diff --git a/rowers/templates/workout_courses.html b/rowers/templates/workout_courses.html new file mode 100644 index 00000000..1a177d37 --- /dev/null +++ b/rowers/templates/workout_courses.html @@ -0,0 +1,79 @@ +{% extends "newbase.html" %} +{% load static %} +{% load rowerfilters %} +{% load leaflet_tags %} + +{% block meta %} +{% leaflet_js %} +{% leaflet_css %} +{% endblock %} + +{% block scripts %} + +{% endblock %} + +{% block title %}{{ workout.name }} {% endblock %} +{% block og_title %}{{ workout.name }} {% endblock %} +{% block description %}{{ workout.name }} +{{ workout.date }} - {{ workout.distance }}m - {{ workout.duration |durationprint:"%H:%M:%S.%f" }}{% endblock %} +{% block og_description %}{{ workout.name }} +{{ workout.date }} - {{ workout.distance }}m - {{ workout.duration |durationprint:"%H:%M:%S.%f" }}{% endblock %} + + + +{% block main %} + +

    {{ workout.name }}

    + + +{% endblock %} + +{% block sidebar %} +{% include 'menu_workout.html' %} +{% endblock %} diff --git a/rowers/urls.py b/rowers/urls.py index 2a30043a..7e07eeb3 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -650,6 +650,8 @@ urlpatterns = [ re_path(r'^register/thankyou/$', TemplateView.as_view(template_name='registerthankyou.html'), name='registerthankyou'), re_path(r'^workout/(?P\b[0-9A-Fa-f]+\b)/workflow/$',views.workout_workflow_view, name='workout_workflow_view'), + re_path(r'^workout/(?P\b[0-9A-Fa-f]+\b)/courses/$',views.workout_course_view, + name='workout_course_view'), re_path(r'^workout/(?P\b[0-9A-Fa-f]+\b)/flexchart/(?P[\w\ ]+.*)/(?P[\w\ ]+.*)/(?P[\w\ ]+.*)/(?P\w+)/$',views.workout_flexchart3_view,name='workout_flexchart3_view'), re_path(r'^workout/(?P\b[0-9A-Fa-f]+\b)/flexchart/(?P\w+.*)/(?P[\w\ ]+.*)/(?P[\w\ ]+.*)/(?P\w+.*)/$',views.workout_flexchart3_view,name='workout_flexchart3_view'), re_path(r'^workout/(?P\b[0-9A-Fa-f]+\b)/flexchart/(?P\w+.*)/(?P[\w\ ]+.*)/(?P[\w\ ]+.*)/$',views.workout_flexchart3_view,name='workout_flexchart3_view'), diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 06b7e6d5..3d43e00f 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -6058,6 +6058,54 @@ def workout_fusion_view(request,id1=0,id2=1): 'workout2':w2, }) +# See attached courses +@login_required() +@permission_required('workout.change_workout',fn=get_workout_by_opaqueid, raise_exception=True) +def workout_course_view(request, id): + row = get_workout_by_opaqueid(request,id) + r = getrower(request.user) + breadcrumbs = [ + { + 'url':'/rowers/list-workouts/', + 'name':'Workouts' + }, + { + 'url':get_workout_default_page(request,encoder.encode_hex(row.id)), + 'name': row.name + }, + { + 'url':reverse('workout_course_view',kwargs={'id':id}), + 'name': 'Measured Courses' + } + + ] + + courses = [] + courseselecform = CourseSelectForm() + has_latlon,lat_mean,lon_mean = dataprep.workout_has_latlon(row.id) + if has_latlon: + courses = getnearestcourses([lat_mean,lon_mean],GeoCourse.objects.all(),whatisnear=25, + strict=True) + courseselectform = CourseSelectForm(choices=courses) + + # get results + records = VirtualRaceResult.objects.filter( + course__isnull=False, + workoutid=row.id, + coursecompleted=True).order_by("duration","-distance") + + + return render(request, 'workout_courses.html', + {'workout':row, + 'rower':r, + 'breadcrumbs':breadcrumbs, + 'active':'nav-workouts', + 'teams':get_my_teams(request.user), + 'courses':courses, + 'courseselectform':courseselectform, + 'records':records, + }) + # Edit the splits/summary @login_required() From db7b289209dc83cbec2ac980ca6bcd05458bc8c4 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 14 Oct 2021 07:55:25 +0200 Subject: [PATCH 2/5] bug fix --- rowers/views/workoutviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 3d43e00f..66a982cf 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -6081,7 +6081,7 @@ def workout_course_view(request, id): ] courses = [] - courseselecform = CourseSelectForm() + courseselectform = CourseSelectForm() has_latlon,lat_mean,lon_mean = dataprep.workout_has_latlon(row.id) if has_latlon: courses = getnearestcourses([lat_mean,lon_mean],GeoCourse.objects.all(),whatisnear=25, From eb86364434899b6aebe1415ab51b22e0d498a4a3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 14 Oct 2021 08:33:23 +0200 Subject: [PATCH 3/5] checking race course message linking to job status --- rowers/templates/workout_courses.html | 30 +++++++++++++- rowers/views/statements.py | 1 + rowers/views/workoutviews.py | 60 ++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/rowers/templates/workout_courses.html b/rowers/templates/workout_courses.html index 1a177d37..1d0d46f0 100644 --- a/rowers/templates/workout_courses.html +++ b/rowers/templates/workout_courses.html @@ -9,7 +9,7 @@ {% endblock %} {% block scripts %} - +{% include "monitorjobs.html" %} {% endblock %} {% block title %}{{ workout.name }} {% endblock %} @@ -25,7 +25,6 @@

    {{ workout.name }}

      -
    • {% if records %}
    • Course Results

      @@ -48,6 +47,33 @@
    • {% endif %} + {% if courses %} +
    • +

      Interval by Course

      +

      + This functionality allows you to record a time on a set course that you've rowed during the workout. + The summary will be updated to show time on course, and you can compare this with other + attempts. +

      +

      + {% if rower.share_course_results %} + You are currently sharing your course results with all Rowsandall users. + Click here to hide your course results. + {% else %} + You are currently hiding your course results (except for your participation in online challenges). + Click here to hide your course results. + {% endif %} +

      +
      + + {{ courseselectform.as_table }} +
      + {% csrf_token %} + +
      +
    • + {% endif %} +
    • diff --git a/rowers/views/statements.py b/rowers/views/statements.py index 367e5b6f..d386d6a9 100644 --- a/rowers/views/statements.py +++ b/rowers/views/statements.py @@ -765,6 +765,7 @@ verbose_job_status = { 'long_test_task2': 'Long Test Task 2', 'update_empower': 'Correct Empower Inflated Power Bug', 'submit_race': 'Checking Race Course Result', + 'check_race_course': 'Checking Course Result', } def get_job_status(jobid): # pragma: no cover diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 66a982cf..f88f8938 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -6088,13 +6088,63 @@ def workout_course_view(request, id): strict=True) courseselectform = CourseSelectForm(choices=courses) + + + if request.method == 'POST': + courseselectform = CourseSelectForm(request.POST,choices=courses) + if courseselectform.is_valid(): + course = courseselectform.cleaned_data['course'] + # get or create a record + records = VirtualRaceResult.objects.filter( + userid=r.id, + course=course, + workoutid=row.id + ) + if records: + record = records[0] + else: + # create record + record = VirtualRaceResult( + userid = r.id, + username = r.user.first_name+' '+r.user.last_name, + workoutid = row.id, + weightcategory = r.weightcategory, + adaptiveclass = r.adaptiveclass, + course = course, + distance = course.distance, + boatclass = row.workouttype, + boattype = row.boattype, + sex = r.sex, + age = calculate_age(r.birthdate), + ) + record.save() + + job = myqueue( + queuehigh, + handle_check_race_course, + row.csvfilename, + row.id, + course.id, + record.id, + r.user.email, + r.user.first_name, + summary=True, + successemail=True, + ) + + try: + request.session['async_tasks'] += [(job.id,'check_race_course')] + except KeyError: + request.session['async_tasks'] = [(job.id,'check_race_course')] + + messages.info(request,'We are checking your time on the course in the background. You will receive an email when the check is complete. You can check the status here') + # get results records = VirtualRaceResult.objects.filter( course__isnull=False, workoutid=row.id, coursecompleted=True).order_by("duration","-distance") - return render(request, 'workout_courses.html', {'workout':row, 'rower':r, @@ -6277,7 +6327,13 @@ def workout_summary_edit_view(request,id,message="",successmessage="" summary=True, successemail=True, ) - messages.info(request,'We are checking your time on the course in the background') + + try: + request.session['async_tasks'] += [(job.id,'check_race_course')] + except KeyError: + request.session['async_tasks'] = [(job.id,'check_race_course')] + + messages.info(request,'We are checking your time on the course in the background. You will receive an email when the check is complete. You can check the status here') vals = None # feeling lucky / ruptures From a08f7ff12240d1587e9ab717828b5da9c5463c97 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 14 Oct 2021 08:40:54 +0200 Subject: [PATCH 4/5] design of new page --- rowers/templates/workout_courses.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rowers/templates/workout_courses.html b/rowers/templates/workout_courses.html index 1d0d46f0..98a79928 100644 --- a/rowers/templates/workout_courses.html +++ b/rowers/templates/workout_courses.html @@ -48,8 +48,8 @@ {% endif %} {% if courses %} -
    • -

      Interval by Course

      +
    • +

      Add a course

      This functionality allows you to record a time on a set course that you've rowed during the workout. The summary will be updated to show time on course, and you can compare this with other @@ -74,6 +74,7 @@

    • {% endif %}
    • +

      Workout Summary

    • Rower:{{ first_name }} {{ last_name }}
      From f7d3585bb9a33383459e0a9695627e23e4a997e3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 14 Oct 2021 08:43:24 +0200 Subject: [PATCH 5/5] removing reload --- rowers/templates/workout_courses.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rowers/templates/workout_courses.html b/rowers/templates/workout_courses.html index 98a79928..3417d21a 100644 --- a/rowers/templates/workout_courses.html +++ b/rowers/templates/workout_courses.html @@ -9,7 +9,7 @@ {% endblock %} {% block scripts %} -{% include "monitorjobs.html" %} + {% endblock %} {% block title %}{{ workout.name }} {% endblock %}
      Rower:{{ first_name }} {{ last_name }}