diff --git a/app.py b/app.py
index 0f6106f..ee669f7 100644
--- a/app.py
+++ b/app.py
@@ -104,14 +104,89 @@ def delete_person(person_id):
@ app.route("/exercise", methods=['POST'])
def create_exercise():
name = request.form.get("name")
- db.create_exercise(name)
- return redirect(url_for('settings'))
+ new_exercise_id = db.create_exercise(name)
+ return f"""
+
+ |
+ {name}
+ |
+
+
+ Edit
+
+
+ Remove
+
+ |
+
+ """
-@ app.route("/exercise//delete", methods=['GET', 'POST'])
+@ app.route("/exercise/", methods=['GET'])
+def get_exercise(exercise_id):
+ exercise = db.get_exercise(exercise_id)
+ return f"""
+
+ |
+ {exercise['Name']}
+ |
+
+
+ Edit
+
+
+ Remove
+
+ |
+
+ """
+
+
+@ app.route("/exercise//edit_form", methods=['GET'])
+def get_exercise_edit_form(exercise_id):
+ exercise = db.get_exercise(exercise_id)
+ return f"""
+
+ |
+
+ |
+
+
+ Update
+
+
+ Cancel
+
+ |
+
+ """
+
+
+@ app.route("/exercise//update", methods=['PUT'])
+def update_exercise(exercise_id):
+ new_name = request.form.get('name')
+ db.update_exercise(exercise_id, new_name)
+ return f"""
+
+ |
+ {new_name}
+ |
+
+
+ Edit
+
+
+ Remove
+
+ |
+
+ """
+
+
+@ app.route("/exercise//delete", methods=['DELETE'])
def delete_exercise(exercise_id):
db.delete_exercise(exercise_id)
- return redirect(url_for('settings'))
+ return ""
@ app.route("/settings")
diff --git a/db.py b/db.py
index 7653cae..dcbf04d 100644
--- a/db.py
+++ b/db.py
@@ -36,14 +36,24 @@ class DataBase():
'SELECT ExerciseId AS "ExerciseId", Name AS "Name" FROM Exercise')
return [{"ExerciseId": e['ExerciseId'], "Name": e['Name']} for e in exercises]
+ def get_exercise(self, exercise_id):
+ exercise = self.execute(
+ 'SELECT ExerciseId AS "ExerciseId", Name AS "Name" FROM Exercise WHERE ExerciseId=%s LIMIT 1', [exercise_id], one=True)
+ return exercise
+
def create_exercise(self, name):
- self.execute('INSERT INTO Exercise (Name) VALUES (%s)',
- [name], commit=True)
+ new_exercise = self.execute('INSERT INTO Exercise (Name) VALUES (%s) RETURNING ExerciseId AS "ExerciseId"',
+ [name], commit=True, one=True)
+ return new_exercise['ExerciseId']
def delete_exercise(self, exercise_id):
self.execute('DELETE FROM Exercise WHERE ExerciseId=%s', [
exercise_id], commit=True)
+ def update_exercise(self, exercise_id, name):
+ self.execute('UPDATE Exercise SET Name=%s WHERE ExerciseId=%s', [
+ name, exercise_id], commit=True)
+
def get_people(self):
people = self.execute(
'SELECT PersonId AS "PersonId", Name AS "Name" FROM Person')
diff --git a/static/css/style.css b/static/css/style.css
new file mode 100644
index 0000000..66b26e0
--- /dev/null
+++ b/static/css/style.css
@@ -0,0 +1,4 @@
+tr.htmx-swapping td {
+ opacity: 0;
+ transition: opacity 0.5s ease-out;
+}
\ No newline at end of file
diff --git a/templates/base.html b/templates/base.html
index cfda831..2f4c1e0 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -11,6 +11,8 @@
+
+