diff --git a/app.py b/app.py index 0f2f9ec..cd41f82 100644 --- a/app.py +++ b/app.py @@ -133,15 +133,36 @@ def create_topset(person_id, workout_id): repetitions = request.form.get("repetitions") weight = request.form.get("weight") - db.create_topset(workout_id, exercise_id, repetitions, weight) - return redirect(url_for('get_workout', person_id=person_id, workout_id=workout_id)) + new_top_set_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 + + + + """ -@ app.route("/person//workout//topset//delete", methods=['GET', 'DELETE']) +@ app.route("/person//workout//topset//delete", methods=['DELETE']) @ validate_topset def delete_topset(person_id, workout_id, topset_id): db.delete_topset(topset_id) - return redirect(url_for('get_workout', person_id=person_id, workout_id=workout_id)) + return "" @ app.route("/person", methods=['POST']) diff --git a/db.py b/db.py index 133483d..4721b43 100644 --- a/db.py +++ b/db.py @@ -100,8 +100,9 @@ class DataBase(): exercise_id, repetitions, weight, topset_id], commit=True) def create_topset(self, workout_id, exercise_id, repetitions, weight): - self.execute('INSERT INTO TopSet (WorkoutId, ExerciseId, Repetitions, Weight) VALUES (%s, %s, %s, %s)', [ - workout_id, exercise_id, repetitions, weight], commit=True) + new_top_set = self.execute('INSERT INTO TopSet (WorkoutId, ExerciseId, Repetitions, Weight) VALUES (%s, %s, %s, %s) RETURNING TopSetId AS "TopSetId"', [ + workout_id, exercise_id, repetitions, weight], commit=True, one=True) + return new_top_set['TopSetId'] def delete_topset(self, topset_id): self.execute('DELETE FROM TopSet WHERE TopSetId=%s', [ diff --git a/templates/workout.html b/templates/workout.html index 9bb5e9b..b08dfde 100644 --- a/templates/workout.html +++ b/templates/workout.html @@ -50,7 +50,8 @@ - + {% for t in workout['TopSets'] %} @@ -63,7 +64,7 @@ class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2"> Edit - Delete @@ -85,8 +86,8 @@
+ hx-post="{{ url_for('create_topset', person_id=workout['PersonId'], workout_id=workout['WorkoutId']) }}" + hx-swap="beforeend" hx-target="#new-workout">