diff --git a/app.py b/app.py
index 540d85c..29e7921 100644
--- a/app.py
+++ b/app.py
@@ -393,14 +393,14 @@ def get_most_recent_topset_for_exercise(person_id, workout_id):
exercises = db.get_all_exercises()
if not exercise_id:
- return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, has_value=False)
+ return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises)
topset = db.get_most_recent_topset_for_exercise(person_id, exercise_id)
if not topset:
- return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, exercise_id=exercise_id, has_value=False)
+ return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, exercise_id=exercise_id)
(repetitions, weight, exercise_name) = topset
- return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, has_value=True, exercise_id=exercise_id, exercise_name=exercise_name, repetitions=repetitions, weight=weight)
+ return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercise_id=exercise_id, exercise_name=exercise_name, repetitions=repetitions, weight=weight)
def calculate_relative_positions(start_dates):
diff --git a/db.py b/db.py
index 898187e..57398a5 100644
--- a/db.py
+++ b/db.py
@@ -460,22 +460,23 @@ class DataBase():
SELECT
t.repetitions,
t.weight,
- e.name as "exercise_name"
+ e.name AS "exercise_name"
FROM
- topset t JOIN workout w ON t.workout_id = w.workout_id
- JOIN exercise e ON t.exercise_id = e.exercise_id
+ exercise e
+ LEFT JOIN topset t ON e.exercise_id = t.exercise_id
+ LEFT JOIN workout w ON t.workout_id = w.workout_id
WHERE
- w.person_id = %s AND t.exercise_id = %s
+ e.exercise_id = %s AND (w.person_id = %s OR w.person_id IS NULL)
ORDER BY
w.start_date DESC
LIMIT 1;
- """, [person_id, exercise_id], one=True)
+ """, [exercise_id, person_id], one=True)
if not topset:
return None
else:
- return (topset['repetitions'], topset['weight'], topset['exercise_name'])
-
+ return (topset.get('repetitions'), topset.get('weight'), topset['exercise_name'])
+
def get_all_exercises(self):
exercises = self.execute(
'SELECT exercise_id, name FROM exercise')
diff --git a/templates/partials/exercise/exercise_select.html b/templates/partials/exercise/exercise_select.html
index 99e1763..14518cf 100644
--- a/templates/partials/exercise/exercise_select.html
+++ b/templates/partials/exercise/exercise_select.html
@@ -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"
id="exercise-search" type="search" name="query" placeholder="Search exercises..."
hx-get="{{ url_for('get_exercises', person_id=person_id) }}" hx-target="#exercise-results"
- hx-trigger="keyup changed delay:500ms" hx-swap="innerHTML" autocomplete="off" {% if has_value==True %}
+ hx-trigger="keyup changed delay:500ms" hx-swap="innerHTML" autocomplete="off" {% if exercise_name %}
value="{{ exercise_name }}" {% endif %} _="
on input
if this.value is empty
@@ -15,7 +15,7 @@
-
\ No newline at end of file
diff --git a/templates/partials/new_set_form.html b/templates/partials/new_set_form.html
index 913fcac..4d85e2e 100644
--- a/templates/partials/new_set_form.html
+++ b/templates/partials/new_set_form.html
@@ -12,7 +12,7 @@
- {{ render_partial('partials/exercise/exercise_select.html', person_id=person_id, has_value=has_value,
+ {{ render_partial('partials/exercise/exercise_select.html', person_id=person_id,
exercise_id=exercise_id, exercise_name=exercise_name) }}
@@ -22,7 +22,7 @@
@@ -32,7 +32,7 @@