Fix issue selecting a new exercise
This commit is contained in:
6
app.py
6
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):
|
||||
|
||||
13
db.py
13
db.py
@@ -460,21 +460,22 @@ 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(
|
||||
|
||||
@@ -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 @@
|
||||
<!-- Results will be injected here -->
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="exercise_id" id="selected-exercise" {% if has_value==True %} value="{{ exercise_id }}" {%
|
||||
<input type="hidden" name="exercise_id" id="selected-exercise" {% if exercise_id %} value="{{ exercise_id }}" {%
|
||||
endif %}>
|
||||
|
||||
</div>
|
||||
@@ -12,7 +12,7 @@
|
||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
|
||||
Exercise
|
||||
</label>
|
||||
{{ 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) }}
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</label>
|
||||
<input
|
||||
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="grid-city" type="number" name="repetitions" {% if has_value==True %} placeholder="{{ repetitions }}"
|
||||
id="grid-city" type="number" name="repetitions" {% if repetitions %} placeholder="{{ repetitions }}"
|
||||
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
||||
</div>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</label>
|
||||
<input
|
||||
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="grid-zip" type="number" name="weight" step="any" {% if has_value==True %} placeholder="{{ weight }}"
|
||||
id="grid-zip" type="number" name="weight" step="any" {% if weight %} placeholder="{{ weight }}"
|
||||
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user