Move exercise filter into person endpoint, needs further refactor
This commit is contained in:
25
app.py
25
app.py
@@ -33,7 +33,20 @@ def get_person_list():
|
||||
@ app.route("/person/<int:person_id>")
|
||||
@ validate_person
|
||||
def get_person(person_id):
|
||||
selected_exercise_ids = [int(i)
|
||||
for i in request.args.getlist('exercise_id')]
|
||||
person = db.get_person(person_id)
|
||||
|
||||
if selected_exercise_ids:
|
||||
filtered_exercises = filter(
|
||||
lambda e: e['ExerciseId'] in selected_exercise_ids, person['Exercises'])
|
||||
person['FilteredExercises'] = list(filtered_exercises)
|
||||
if htmx:
|
||||
return render_template('partials/page/person.html',
|
||||
person=person, is_filtered=True, selected_exercise_ids=selected_exercise_ids), 200, {"HX-Trigger": "updatedPeople"}
|
||||
|
||||
return render_template('person.html', person=person, is_filtered=True, selected_exercise_ids=selected_exercise_ids)
|
||||
|
||||
if htmx:
|
||||
return render_template('partials/page/person.html',
|
||||
person=person, is_filtered=False), 200, {"HX-Trigger": "updatedPeople"}
|
||||
@@ -41,18 +54,6 @@ def get_person(person_id):
|
||||
return render_template('person.html', person=person)
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/exercise_filter", methods=['POST'])
|
||||
@ validate_person
|
||||
def filter_exercises_for_person(person_id):
|
||||
selected_exercise_ids = [int(i)
|
||||
for i in request.form.getlist('exercise_id')]
|
||||
person = db.get_person(person_id)
|
||||
filtered_exercises = filter(
|
||||
lambda e: e['ExerciseId'] in selected_exercise_ids, person['Exercises'])
|
||||
person['FilteredExercises'] = list(filtered_exercises)
|
||||
return render_template('partials/page/person.html', person=person, is_filtered=True, selected_exercise_ids=selected_exercise_ids)
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/workout", methods=['POST'])
|
||||
@ validate_person
|
||||
def create_workout(person_id):
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
{% set exercise_list = person['FilteredExercises'] if is_filtered else person['Exercises'] %}
|
||||
|
||||
{% for e in person['Exercises'] %}
|
||||
<div class="flex items-center mr-4"
|
||||
hx-post="{{ url_for('filter_exercises_for_person', person_id=person['PersonId']) }}"
|
||||
hx-include="[name='exercise_id']" hx-target="#container">
|
||||
<div class="flex items-center mr-4" hx-get="{{ url_for('get_person', person_id=person['PersonId']) }}"
|
||||
hx-include="[name='exercise_id']" hx-target="#container" hx-push-url="true">
|
||||
<input {{ is_checked(e['ExerciseId'], selected_exercise_ids) }} type="checkbox" name="exercise_id"
|
||||
value="{{ e['ExerciseId'] }}"
|
||||
class="w-4 h-4 text-blue-600 bg-gray-100 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
{% block content %}
|
||||
|
||||
{{ render_partial('partials/page/person.html',
|
||||
person=person, is_filtered=False) }}
|
||||
person=person, is_filtered=is_filtered or False, selected_exercise_ids=selected_exercise_ids) }}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user