diff --git a/app.py b/app.py index 8b03b48..0e4e836 100644 --- a/app.py +++ b/app.py @@ -120,25 +120,7 @@ def get_workout_start_date(person_id, workout_id): @ validate_topset def get_topset(person_id, workout_id, topset_id): topset = db.get_topset(person_id, workout_id, topset_id) - return f""" - - - { topset['ExerciseName'] } - - - { topset['Repetitions'] } x { topset['Weight'] }kg - - - Edit - - - Delete - - - - """ + return render_template('partials/person.html', topset=topset, exercises=exercises) @ app.route("/person//workout//topset//edit_form", methods=['GET']) @@ -146,7 +128,7 @@ def get_topset(person_id, workout_id, topset_id): def get_topset_edit_form(person_id, workout_id, topset_id): exercises = db.get_exercises() topset = db.get_topset(person_id, workout_id, topset_id) - return render_template('partials/topset.html', topset=topset, exercises=exercises) + return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercises=exercises, repetitions=topset['Repetitions'], weight=topset['Weight'], is_edit=True) @ app.route("/person//workout//topset", methods=['POST']) @@ -156,29 +138,11 @@ def create_topset(person_id, workout_id): repetitions = request.form.get("repetitions") weight = request.form.get("weight") - new_top_set_id = db.create_topset( + new_topset_id = db.create_topset( workout_id, exercise_id, repetitions, weight) exercise = db.get_exercise(exercise_id) - return f""" - - - { exercise['Name'] } - - - {repetitions} x {weight}kg - - - Edit - - - Delete - - - - """ + 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) @ app.route("/person//workout//topset/", methods=['PUT']) @@ -191,25 +155,7 @@ def update_topset(person_id, workout_id, topset_id): db.update_topset(exercise_id, repetitions, weight, topset_id) exercise = db.get_exercise(exercise_id) - return f""" - - - { exercise['Name'] } - - - {repetitions} x {weight}kg - - - Edit - - - Delete - - - - """ + return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercise_name=exercise['Name'], repetitions=repetitions, weight=weight) @ app.route("/person//workout//topset//delete", methods=['DELETE']) diff --git a/templates/partials/topset.html b/templates/partials/topset.html index 291d8f6..bdc80b6 100644 --- a/templates/partials/topset.html +++ b/templates/partials/topset.html @@ -1,36 +1,56 @@ - - + + + {% if is_edit|default(false, true) == false %} + {{ exercise_name }} + {% else %} - - + {% endif %} + + + {% if is_edit|default(false, true) == false %} + {{ repetitions }} x {{ weight }}kg + {% else %}
+ name="repetitions" value="{{ repetitions }}">

x

+ name="weight" value="{{ weight }}">

kg

+ {% endif %} - - + {% if is_edit|default(false, true) == false %} + + Edit + + + Delete + + {% else %} + Update - Cancel + {% endif %} + \ No newline at end of file diff --git a/templates/workout.html b/templates/workout.html index e63b73f..035f42c 100644 --- a/templates/workout.html +++ b/templates/workout.html @@ -52,23 +52,10 @@ {% for t in workout['TopSets'] %} - - - {{ t['ExerciseName'] }} - - - {{ t['Repetitions'] }} x {{ t['Weight'] }}kg - - - Edit - - - Delete - - - + {{ 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 %}