diff --git a/app.py b/app.py index 54ad2c7..b3e5185 100644 --- a/app.py +++ b/app.py @@ -442,7 +442,17 @@ def show_workout(person_id, workout_id): def get_exercises(): query = request.args.get('query') exercises = db.exercises.get(query) - return render_template('partials/exercise_dropdown.html', exercises=exercises) + return render_template('partials/exercise/exercise_dropdown.html', exercises=exercises) + +@app.route("/exercise//edit_name", methods=['GET', 'POST']) +def edit_exercise_name(exercise_id): + exercise = db.exercises.get_exercise(exercise_id) + if request.method == 'GET': + return render_template('partials/exercise/edit_exercise_name.html', exercise=exercise) + else: + updated_name = request.form['name'] + updated_exercise = db.exercises.update_exercise_name(exercise_id, updated_name) + return render_template('partials/exercise/exercise_list_item.html', exercise=updated_exercise) diff --git a/features/exercises.py b/features/exercises.py index 0881995..4d0b846 100644 --- a/features/exercises.py +++ b/features/exercises.py @@ -6,4 +6,15 @@ class Exercises: # Add wildcards to the query search_query = f"%{query}%" exercises = self.execute("SELECT exercise_id, name FROM exercise WHERE LOWER(name) LIKE LOWER(%s) ORDER BY name ASC;", [search_query]) - return exercises \ No newline at end of file + return exercises + + def get_exercise(self, exercise_id): + exercise = self.execute("SELECT exercise_id, name FROM exercise WHERE exercise_id=%s;", [exercise_id], one=True) + return exercise + + def update_exercise_name(self, exercise_id, updated_name): + sql = "UPDATE exercise SET name = %s WHERE exercise_id = %s;" + params = [updated_name, exercise_id] + self.execute(sql, params) + updated_exercise = self.get_exercise(exercise_id) + return updated_exercise diff --git a/templates/partials/exercise/edit_exercise_name.html b/templates/partials/exercise/edit_exercise_name.html new file mode 100644 index 0000000..f03067c --- /dev/null +++ b/templates/partials/exercise/edit_exercise_name.html @@ -0,0 +1,16 @@ +
  • + + + + +
  • \ No newline at end of file diff --git a/templates/partials/exercise/exercise_dropdown.html b/templates/partials/exercise/exercise_dropdown.html new file mode 100644 index 0000000..4fb079d --- /dev/null +++ b/templates/partials/exercise/exercise_dropdown.html @@ -0,0 +1,9 @@ +{% if exercises %} + +{% else %} +
    No results found
    +{% endif %} \ No newline at end of file diff --git a/templates/partials/exercise/exercise_list_item.html b/templates/partials/exercise/exercise_list_item.html new file mode 100644 index 0000000..aedcc57 --- /dev/null +++ b/templates/partials/exercise/exercise_list_item.html @@ -0,0 +1,14 @@ +
  • + + {{ exercise.name }} + + + + + + + +
  • \ No newline at end of file diff --git a/templates/partials/exercise_dropdown.html b/templates/partials/exercise_dropdown.html deleted file mode 100644 index 40025f4..0000000 --- a/templates/partials/exercise_dropdown.html +++ /dev/null @@ -1,5 +0,0 @@ -{% for e in exercises %} - -{% endfor %} \ No newline at end of file diff --git a/templates/workout.html b/templates/workout.html index bb1b06e..565eb71 100644 --- a/templates/workout.html +++ b/templates/workout.html @@ -95,11 +95,18 @@ - -
    +
    + + + +
    + +