From cafd3f6151a6c673163755400b40597b6d3476bc Mon Sep 17 00:00:00 2001 From: stilbruch Date: Wed, 6 Apr 2022 15:02:25 -0500 Subject: Workouts names can be edited --- app/routes.py | 35 ++++++++++++++++++--- app/static/css/style.css | 4 +++ app/templates/home.html | 10 +++++- app/templates/workout/create.html | 66 ++++++++++++++++++++------------------- 4 files changed, 78 insertions(+), 37 deletions(-) diff --git a/app/routes.py b/app/routes.py index 8a2346a..1ff1023 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,5 +1,5 @@ from app import app, db -from flask import render_template, redirect, url_for, flash +from flask import render_template, redirect, request, url_for, flash from flask_login import current_user, login_user, login_required, logout_user from forms import LoginForm, RegisterForm, WorkoutCreateForm from tables import User, Workout @@ -80,7 +80,34 @@ def createWorkout(): return render_template('workout/create.html', form=form) -@app.route("/workout/manage", methods=['GET']) +@app.route("/workout/edit", methods=['GET', 'POST']) @login_required -def manageWorkout(): - return render_template('workout/manage.html') +def editWorkout(): + # Id is required + if 'id' not in request.args: + return redirect(url_for('home')) + + # Validate Id + workout = Workout.query.filter_by(id=int(request.args['id']), user_id=current_user.id).first() + if not workout: + return redirect(url_for('home')) + + form = WorkoutCreateForm() + + if form.validate_on_submit(): + # Form has been submitted, write changes + + workout.name = form.name.data + # TODO: Add exercise changes + + # Write changes to database + db.session.commit() + return redirect(url_for('home')); + else: + form.name.data = workout.name + form.exercises.pop_entry() # TODO: better way to do this? + + for exercise in workout.exercises: + form.exercises.append_entry(exercise) + + return render_template('workout/create.html', form=form) diff --git a/app/static/css/style.css b/app/static/css/style.css index 497a2bf..e5eb7a3 100644 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -10,3 +10,7 @@ -o-background-size: cover; background-size: cover; } + +.welcome { + background: linear-gradient(to right, #5B86E5, #36D1DC); +} diff --git a/app/templates/home.html b/app/templates/home.html index 693e03b..11179cd 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -60,13 +60,21 @@ {{ workout.name }} {{ workout.exercises.count() }} exercises - Edit + +

+ Edit + Delete +

+ {% endfor %} +
diff --git a/app/templates/workout/create.html b/app/templates/workout/create.html index eaf5f39..cdd1191 100644 --- a/app/templates/workout/create.html +++ b/app/templates/workout/create.html @@ -7,7 +7,7 @@

- + @@ -16,39 +16,41 @@

-
-
-
-

- - - + {% for entry in form.exercises.entries %} +

+
+
+

+ + + + +

+
+
+

+ + + + +

+
+
+

+ + + + +

+
+

+ +

-
-

- - - - -

-
-
-

- - - - -

-
-

- - - -

-
+ {% endfor %}

@@ -69,12 +71,11 @@