From 339781355d0cdeb44ecb7c5779902a38aec55c42 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Thu, 24 Nov 2022 21:19:16 +1100 Subject: [PATCH] Make workout and person pages htmx driven --- app.py | 15 +++- templates/partials/page/person.html | 24 +++--- templates/partials/page/workout.html | 117 ++++++++++++++++++++++++++ templates/workout.html | 118 +-------------------------- 4 files changed, 142 insertions(+), 132 deletions(-) create mode 100644 templates/partials/page/workout.html diff --git a/app.py b/app.py index 64d6bc7..5ba55cd 100644 --- a/app.py +++ b/app.py @@ -57,6 +57,10 @@ def filter_exercises_for_person(person_id): @ validate_person def create_workout(person_id): new_workout_id = db.create_workout(person_id) + if htmx: + workout = db.get_workout(person_id, new_workout_id) + return render_template('partials/page/workout.html', + workout=workout), 200, {"HX-Trigger": "updatedPeople", "HX-Push": url_for('get_workout', person_id=person_id, workout_id=new_workout_id)} return redirect(url_for('get_workout', person_id=person_id, workout_id=new_workout_id)) @@ -64,14 +68,19 @@ def create_workout(person_id): @ validate_workout def get_workout(person_id, workout_id): workout = db.get_workout(person_id, workout_id) + if htmx: + return render_template('partials/page/workout.html', + workout=workout), 200, {"HX-Trigger": "updatedPeople"} return render_template('workout.html', workout=workout) -@ app.route("/person//workout//delete", methods=['GET', 'DELETE']) +@ app.route("/person//workout//delete", methods=['DELETE']) @ validate_workout def delete_workout(person_id, workout_id): db.delete_workout(workout_id) - return redirect(url_for('get_person', person_id=person_id)) + person = db.get_person(person_id) + return render_template('partials/page/person.html', + person=person, is_filtered=False), 200, {"HX-Trigger": "updatedPeople", "HX-Push": url_for('get_person', person_id=person_id)} @ app.route("/person//workout//start_date_edit_form", methods=['GET']) @@ -122,7 +131,7 @@ def create_topset(person_id, workout_id): workout_id, exercise_id, repetitions, weight) exercise = db.get_exercise(exercise_id) - return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=new_topset_id, exercise_name=exercise['Name'], repetitions=repetitions, weight=weight) + return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=new_topset_id, exercise_name=exercise['Name'], repetitions=repetitions, weight=weight), 200, {"HX-Trigger": "topsetAdded"} @ app.route("/person//workout//topset/", methods=['PUT']) diff --git a/templates/partials/page/person.html b/templates/partials/page/person.html index e8a44ad..9f4cbcd 100644 --- a/templates/partials/page/person.html +++ b/templates/partials/page/person.html @@ -7,11 +7,10 @@ List of workouts
-
- -
+
@@ -77,18 +76,17 @@ {% endfor %} - Edit -
- -
+ {% endfor %} diff --git a/templates/partials/page/workout.html b/templates/partials/page/workout.html new file mode 100644 index 0000000..191446d --- /dev/null +++ b/templates/partials/page/workout.html @@ -0,0 +1,117 @@ +
+ +
+
+

{{ workout['PersonName'] }}

+
+ +
+ +
+ {{ render_partial('partials/start_date.html', person_id=workout['PersonId'], workout_id=workout['WorkoutId'], + start_date=workout['StartDate']) }} +
+ +
+ +
+
+

Top Sets

+ +
+
+ + + + + + + + + + + {% for t in workout['TopSets'] %} + {{ render_partial('partials/topset.html', person_id=workout['PersonId'], + workout_id=workout['WorkoutId'], + topset_id=t['TopSetId'], exercise_name=t['ExerciseName'], repetitions=t['Repetitions'], + weight=t['Weight']) }} + {% endfor %} + +
+ Exercise + Top Set +
+ + {% if workout['TopSets']|length == 0 %} + + {% endif %} +
+
+ +
+
+
+ +
+
+ +
+ +
+ + + +
+
+
+ +
+ + +
+ +
+ + +
+
+ +
+
+
\ No newline at end of file diff --git a/templates/workout.html b/templates/workout.html index b11a521..56a50d9 100644 --- a/templates/workout.html +++ b/templates/workout.html @@ -2,122 +2,8 @@ {% block content %} -
+{{ render_partial('partials/page/workout.html', +workout=workout) }} -
-
-

{{ workout['PersonName'] }}

-
-
- -
-
- -
- {{ render_partial('partials/start_date.html', person_id=workout['PersonId'], workout_id=workout['WorkoutId'], - start_date=workout['StartDate']) }} -
- -
- -
-
-

Top Sets

- -
-
- - - - - - - - - - - {% for t in workout['TopSets'] %} - {{ render_partial('partials/topset.html', person_id=workout['PersonId'], - workout_id=workout['WorkoutId'], - topset_id=t['TopSetId'], exercise_name=t['ExerciseName'], repetitions=t['Repetitions'], - weight=t['Weight']) }} - {% endfor %} - -
- Exercise - Top Set -
- - {% if workout['TopSets']|length == 0 %} - - {% endif %} -
-
- -
-
-
- -
-
- -
- -
- - - -
-
-
- -
- - -
- -
- - -
-
- -
-
-
{% endblock %} \ No newline at end of file