diff --git a/app.py b/app.py index 6a38f5a..7652379 100644 --- a/app.py +++ b/app.py @@ -32,6 +32,18 @@ def get_person(person_id): return render_template('person.html', person=person) +@app.route("/person//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//workout", methods=['POST']) @ validate_person def create_workout(person_id): @@ -213,7 +225,12 @@ def my_utility_processor(): return element return None - return dict(get_list_of_people_and_workout_count=get_list_of_people_and_workout_count, is_selected_page=is_selected_page, get_first_element_from_list_with_matching_attribute=get_first_element_from_list_with_matching_attribute) + def is_checked(val, checked_vals): + if not checked_vals: + return 'checked' + return 'checked' if val in checked_vals else '' + + return dict(get_list_of_people_and_workout_count=get_list_of_people_and_workout_count, is_selected_page=is_selected_page, get_first_element_from_list_with_matching_attribute=get_first_element_from_list_with_matching_attribute, is_checked=is_checked) if __name__ == '__main__': diff --git a/templates/partials/page/person.html b/templates/partials/page/person.html new file mode 100644 index 0000000..72ea1c7 --- /dev/null +++ b/templates/partials/page/person.html @@ -0,0 +1,116 @@ +
+
+
+ +
+
+

{{ person['PersonName'] }}

+ List of workouts +
+
+
+ +
+
+
+ +
+ {% set exercise_list = person['FilteredExercises'] if is_filtered else person['Exercises'] %} + + {% for e in person['Exercises'] %} +
+ + +
+ {% endfor %} +
+ +
+
+
+
+ + {% if person['Workouts']|length > 0 %} + + + + + {% for e in exercise_list %} + + {% endfor %} + + + + + + {% for w in person['Workouts'] %} + + + + {% for e in exercise_list %} + + {% endfor %} + + + + {% endfor %} + + +
+ Date + + {{ e['ExerciseName'] }} + +
+ {{ w['StartDate'] }} + + {% set topset_exercise = + get_first_element_from_list_with_matching_attribute(w['TopSets'], + 'ExerciseId', + e['ExerciseId']) %} + {% if topset_exercise %} + {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg + {% endif %} + + + Edit + + +
+ +
+
+ {% endif %} + + {% if person['Workouts']|length == 0 %} + + {% endif %} + +
+
+
+
+
+
+ + {{ render_partial('partials/stats.html', stats=person['Stats']) }} +
\ No newline at end of file diff --git a/templates/person.html b/templates/person.html index 3bc8da2..dac7e14 100644 --- a/templates/person.html +++ b/templates/person.html @@ -1,101 +1,8 @@ {% extends 'base.html' %} {% block content %} -
-
-
-
-

{{ person['PersonName'] }}

- List of workouts -
-
-
- -
-
-
- -
-
-
-
- - {% if person['Workouts']|length > 0 %} - - - - - {% for e in person['Exercises'] %} - - {% endfor %} - - - - - - {% for w in person['Workouts'] %} - - - - {% for e in person['Exercises'] %} - - {% endfor %} - - - - {% endfor %} - - -
- Date - - {{ e['ExerciseName'] }} - -
- {{ w['StartDate'] }} - - {% set topset_exercise = - get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExerciseId', - e['ExerciseId']) %} - {% if topset_exercise %} - {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg - {% endif %} - - - Edit - - -
- -
-
- {% endif %} - - {% if person['Workouts']|length == 0 %} - - {% endif %} - -
-
-
-
-
-
- -{{ render_partial('partials/stats.html', stats=person['Stats']) }} +{{ render_partial('partials/page/person.html', +person=person, is_filtered=False) }} {% endblock %} \ No newline at end of file