diff --git a/app.py b/app.py index cd41f82..c2877cd 100644 --- a/app.py +++ b/app.py @@ -110,20 +110,37 @@ def get_workout_start_date(person_id, workout_id): """ -@ app.route("/person//workout//topset/", methods=['GET', 'POST']) +@ app.route("/person//workout//topset/", methods=['GET']) @ validate_topset def get_topset(person_id, workout_id, topset_id): - if request.method == 'POST': - exercise_id = request.form.get("exercise_id") - repetitions = request.form.get("repetitions") - weight = request.form.get("weight") - - db.update_topset(exercise_id, repetitions, weight, topset_id) - - return redirect(url_for('get_workout', person_id=person_id, workout_id=workout_id)) - topset = db.get_topset(person_id, workout_id, topset_id) - return render_template('topset.html', topset=topset) + return f""" + + + { topset['ExerciseName'] } + + + { topset['Repetitions'] } x { topset['Weight'] }kg + + + Edit + + + Delete + + + + """ + + +@ app.route("/person//workout//topset//edit_form", methods=['GET']) +@ validate_topset +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) @ app.route("/person//workout//topset", methods=['POST']) @@ -145,7 +162,7 @@ def create_topset(person_id, workout_id): {repetitions} x {weight}kg - Edit @@ -158,6 +175,38 @@ def create_topset(person_id, workout_id): """ +@ app.route("/person//workout//topset/", methods=['PUT']) +@ validate_workout +def update_topset(person_id, workout_id, topset_id): + exercise_id = request.form.get("exercise_id") + repetitions = request.form.get("repetitions") + weight = request.form.get("weight") + + new_top_set_id = db.update_topset( + workout_id, exercise_id, repetitions, weight) + exercise = db.get_exercise(exercise_id) + + return f""" + + + { exercise['Name'] } + + + {repetitions} x {weight}kg + + + Edit + + + Delete + + + + """ + + @ app.route("/person//workout//topset//delete", methods=['DELETE']) @ validate_topset def delete_topset(person_id, workout_id, topset_id): diff --git a/templates/partials/topset.html b/templates/partials/topset.html new file mode 100644 index 0000000..ebfc0dd --- /dev/null +++ b/templates/partials/topset.html @@ -0,0 +1,33 @@ + + + + + +
+ x kg +
+ + + + Update + + + Cancel + + + \ No newline at end of file diff --git a/templates/topset.html b/templates/topset.html deleted file mode 100644 index d7abec0..0000000 --- a/templates/topset.html +++ /dev/null @@ -1,75 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} - -
- -
-
-

{{ topset['PersonName'] }}

- {{ topset['StartDate'] }} -
- - Delete topset - -
- -
- -
-
-
- -
-
- -
- -
- - - -
-
-
- -
- - -
- -
- - -
-
- -
-
-
- -{% endblock %} \ No newline at end of file diff --git a/templates/workout.html b/templates/workout.html index dc03b9a..c574701 100644 --- a/templates/workout.html +++ b/templates/workout.html @@ -59,7 +59,7 @@ {{ t['Repetitions'] }} x {{ t['Weight'] }}kg - Edit