diff options
| author | stilbruch <stilbruch@protonmail.com> | 2022-04-24 17:59:31 -0500 |
|---|---|---|
| committer | stilbruch <stilbruch@protonmail.com> | 2022-04-24 17:59:31 -0500 |
| commit | 586285028845c8ed9a2e859f1266c233b8278311 (patch) | |
| tree | 8a19025a0f2c9e1c2c9e93fce027fdfd02d5e821 /app/routes | |
| parent | 7c9c647f0e22c42bcce8845f5d49808014d39d96 (diff) | |
| download | Strengthy-586285028845c8ed9a2e859f1266c233b8278311.tar.xz Strengthy-586285028845c8ed9a2e859f1266c233b8278311.zip | |
Fix backend for workout editing
Diffstat (limited to 'app/routes')
| -rw-r--r-- | app/routes/workout.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/app/routes/workout.py b/app/routes/workout.py index a929a6c..ffdacb9 100644 --- a/app/routes/workout.py +++ b/app/routes/workout.py @@ -2,7 +2,7 @@ from app import app, db from flask import render_template, redirect, request, url_for, flash from flask_login import current_user, login_required from forms import WorkoutCreateForm, WorkoutRecordForm -from tables import User, Workout +from tables import Exercise, User, Workout @app.route("/workout/create", methods=["GET", "POST"]) @@ -46,10 +46,23 @@ def workout_edit(): form = WorkoutCreateForm() if form.validate_on_submit(): - # Form has been submitted, write changes + # Form has been submitted, write changes FIXME + for entry in form.exercises.entries: + # Get the specified exercise TODO needs hidden id field + exercise = Exercise.query.filter_by( + workout_id=workout.id, id=int(entry.data["id"]) + ).first() - workout.name = form.name.data - # TODO: Add exercise changes + if not exercise: # NOTE error? + continue + + # Update exercise + exercise.name = entry.data["name"] + exercise.sets = entry.data["sets"] + exercise.units = entry.data["units"] + exercise.type = entry.data["type"] + + print(exercise) # Write changes to database db.session.commit() @@ -83,6 +96,7 @@ def workout_record(): return redirect(url_for("home")) if form.validate_on_submit(): + # Form has been submitted and is valid FIXME print(form) return render_template("workout/record.html", workout=workout, form=form) |
