Fix error thrown when attempting to update exercise name

This commit is contained in:
Peter Stockings
2024-11-04 23:14:56 +11:00
parent 1f0742bbc0
commit 5938c9468b
5 changed files with 15 additions and 12 deletions

8
app.py
View File

@@ -449,18 +449,20 @@ def get_exercises():
@app.route("/exercise/<int:exercise_id>/edit_name", methods=['GET', 'POST']) @app.route("/exercise/<int:exercise_id>/edit_name", methods=['GET', 'POST'])
def edit_exercise_name(exercise_id): def edit_exercise_name(exercise_id):
exercise = db.exercises.get_exercise(exercise_id) exercise = db.exercises.get_exercise(exercise_id)
person_id = request.args.get('person_id', type=int)
if request.method == 'GET': if request.method == 'GET':
return render_template('partials/exercise/edit_exercise_name.html', exercise=exercise) return render_template('partials/exercise/edit_exercise_name.html', exercise=exercise, person_id=person_id)
else: else:
updated_name = request.form['name'] updated_name = request.form['name']
updated_exercise = db.exercises.update_exercise_name(exercise_id, updated_name) updated_exercise = db.exercises.update_exercise_name(exercise_id, updated_name)
return render_template('partials/exercise/exercise_list_item.html', exercise=updated_exercise) return render_template('partials/exercise/exercise_list_item.html', exercise=updated_exercise, person_id=person_id)
@app.route("/exercises/add", methods=['POST']) @app.route("/exercises/add", methods=['POST'])
def add_exercise(): def add_exercise():
exercise_name = request.form['query'] exercise_name = request.form['query']
new_exercise = db.exercises.add_exercise(exercise_name) new_exercise = db.exercises.add_exercise(exercise_name)
return render_template('partials/exercise/exercise_list_item.html', exercise=new_exercise) person_id = request.args.get('person_id', type=int)
return render_template('partials/exercise/exercise_list_item.html', exercise=new_exercise, person_id=person_id)
@ app.route("/exercise/<int:exercise_id>/delete", methods=['DELETE']) @ app.route("/exercise/<int:exercise_id>/delete", methods=['DELETE'])
def delete_exercise(exercise_id): def delete_exercise(exercise_id):

View File

@@ -4,9 +4,9 @@
class="w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-2 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500" class="w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-2 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
_="on click from me call event.stopPropagation()"> _="on click from me call event.stopPropagation()">
<!-- Save Icon --> <!-- Save Icon -->
<button hx-post="{{ url_for('edit_exercise_name', exercise_id=exercise.exercise_id) }}" hx-target="closest li" <button hx-post="{{ url_for('edit_exercise_name', exercise_id=exercise.exercise_id, person_id=person_id) }}"
hx-swap="outerHTML" hx-include="closest li" class="text-gray-500 hover:text-gray-700 ml-2" hx-target="closest li" hx-swap="outerHTML" hx-include="closest li"
_="on click from me call event.stopPropagation()"> class="text-gray-500 hover:text-gray-700 ml-2" _="on click from me call event.stopPropagation()">
<!-- Tick icon SVG --> <!-- Tick icon SVG -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"
stroke-width="2"> stroke-width="2">
@@ -14,8 +14,8 @@
</svg> </svg>
</button> </button>
<!-- Delete Icon --> <!-- Delete Icon -->
<button hx-delete="{{ url_for('delete_exercise', exercise_id=exercise.exercise_id) }}" hx-target="closest li" <button hx-delete="{{ url_for('delete_exercise', exercise_id=exercise.exercise_id, person_id=person_id) }}"
hx-swap="outerHTML" class="text-red-500 hover:text-red-700 ml-2" hx-target="closest li" hx-swap="outerHTML" class="text-red-500 hover:text-red-700 ml-2"
hx-confirm="Are you sure you wish to delete {{ exercise.name }} from exercises?" hx-confirm="Are you sure you wish to delete {{ exercise.name }} from exercises?"
_="on click from me call event.stopPropagation()"> _="on click from me call event.stopPropagation()">
<!-- Trash icon SVG --> <!-- Trash icon SVG -->

View File

@@ -8,7 +8,7 @@
<div class="py-2 px-4 text-gray-500 flex items-center justify-between border border-gray-200"> <div class="py-2 px-4 text-gray-500 flex items-center justify-between border border-gray-200">
<span>No results found</span> <span>No results found</span>
<!-- Add Exercise Button --> <!-- Add Exercise Button -->
<button hx-post="{{ url_for('add_exercise') }}" hx-target="closest div" hx-swap="outerHTML" <button hx-post="{{ url_for('add_exercise', person_id=person_id) }}" hx-target="closest div" hx-swap="outerHTML"
hx-include="[name='query']" class="text-blue-500 hover:text-blue-700 font-semibold" hx-include="[name='query']" class="text-blue-500 hover:text-blue-700 font-semibold"
_="on click from me call event.stopPropagation()"> _="on click from me call event.stopPropagation()">
Add Exercise Add Exercise

View File

@@ -6,8 +6,9 @@
<!-- Exercise Name --> <!-- Exercise Name -->
<span>{{ exercise.name }}</span> <span>{{ exercise.name }}</span>
<!-- Edit Icon --> <!-- Edit Icon -->
<a hx-get="{{ url_for('edit_exercise_name', exercise_id=exercise.exercise_id) }}" hx-target="closest li" <a hx-get="{{ url_for('edit_exercise_name', exercise_id=exercise.exercise_id, person_id=person_id) }}"
hx-swap="outerHTML" class="text-gray-500 hover:text-gray-700" _="on click from me call event.stopPropagation()"> hx-target="closest li" hx-swap="outerHTML" class="text-gray-500 hover:text-gray-700"
_="on click from me call event.stopPropagation()">
<!-- Edit icon SVG --> <!-- Edit icon SVG -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"
stroke-width="2"> stroke-width="2">

View File

@@ -3,7 +3,7 @@
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500" class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
id="exercise-search" type="text" name="query" placeholder="Search exercises..." id="exercise-search" type="text" name="query" placeholder="Search exercises..."
hx-get="{{ url_for('get_exercises', person_id=person_id) }}" hx-target="#exercise-results" hx-get="{{ url_for('get_exercises', person_id=person_id) }}" hx-target="#exercise-results"
hx-trigger="keyup changed delay:200ms" autocomplete="off"> hx-trigger="keyup changed delay:500ms" hx-swap="innerHTML" autocomplete="off">
<!-- Dropdown Menu --> <!-- Dropdown Menu -->
<div id="exercise-results" class="absolute w-full bg-white mt-1 rounded shadow-md z-10"> <div id="exercise-results" class="absolute w-full bg-white mt-1 rounded shadow-md z-10">