From b23e6064d70e7d07957969306f68db7c3db1f716 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Fri, 13 Oct 2023 18:52:47 +1100 Subject: [PATCH] By default only load 5 most recent workouts for list, but on click of button at bottom load them all --- app.py | 19 ++++- .../partials/workouts_list_fragment.html | 74 +++++++++++++++++++ templates/workouts_list.html | 71 +----------------- 3 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 templates/partials/workouts_list_fragment.html diff --git a/app.py b/app.py index 076041b..88ff016 100644 --- a/app.py +++ b/app.py @@ -287,6 +287,14 @@ def calendar_view(user_id): return render_template('partials/calendar.html', calendar_month=calendar_month, user_id=user_id) +@ app.route("/user//workout/list", methods=['GET']) +def workout_list(user_id): + max_date = request.args.get( + 'min_date', default=datetime.now().date(), type=toDate) + workouts = get_workouts_for_user(user_id, max_date=max_date) + return render_template('partials/workouts_list_fragment.html', workouts=workouts, user_id=user_id) + + def render_users_and_workouts(): users = User.query.all() users_data = [] @@ -356,11 +364,16 @@ def render_users_and_workouts(): return render_template('users_and_workouts.html', users=users_data, bikes=Bike.query.all()) -def get_workouts_for_user(user_id): +def get_workouts_for_user(user_id, max_date=None): user = User.query.get(user_id) workouts_data = [] - workouts = Workout.query.filter_by(user_id=user_id).order_by( - Workout.created_at.desc()).all() + workouts = [] + if max_date: + workouts = Workout.query.filter_by(user_id=user_id).filter( + Workout.started_at < max_date).order_by(Workout.created_at.desc()).all() + else: + workouts = Workout.query.filter_by(user_id=user_id).order_by( + Workout.created_at.desc()).all() for workout in workouts: diff --git a/templates/partials/workouts_list_fragment.html b/templates/partials/workouts_list_fragment.html new file mode 100644 index 0000000..a1c20ec --- /dev/null +++ b/templates/partials/workouts_list_fragment.html @@ -0,0 +1,74 @@ +
    + {% for w in workouts %} +
  1. + + + + + + + + +
    +
    + +
    Duration: {{ w.duration }} + | + Average RPM: {{ w.average_rpm + }} | + Calories: {{ w.calories }} | Distance: {{ w.distance }} {% if w.is_heart_rate_available + %} | Average: BPM: {{w.average_bpm }} {% endif %}{{ + w.bike_display_name }}
    +
    + +
    + + +
  2. + {% if loop.index == loop.length %} + +
    + +
    + {% endif %} + + + {% endfor%} + +
\ No newline at end of file diff --git a/templates/workouts_list.html b/templates/workouts_list.html index 281d681..87ed298 100644 --- a/templates/workouts_list.html +++ b/templates/workouts_list.html @@ -65,76 +65,7 @@ {% endif %} \ No newline at end of file