From dc88375d8c0379f913203a71c28ac2b68ab58c38 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sun, 16 Jul 2023 09:54:26 +1000 Subject: [PATCH] Remove wrappers for calendar, dashboard, & person --- app.py | 31 ++- templates/calendar.html | 188 +++++++++++++++++- templates/dashboard.html | 179 ++++++++++++++++- templates/partials/page/calendar.html | 186 ----------------- templates/partials/page/dashboard.html | 176 ---------------- templates/partials/page/person.html | 262 ------------------------ templates/person.html | 265 ++++++++++++++++++++++++- 7 files changed, 647 insertions(+), 640 deletions(-) delete mode 100644 templates/partials/page/calendar.html delete mode 100644 templates/partials/page/dashboard.html delete mode 100644 templates/partials/page/person.html diff --git a/app.py b/app.py index 303b467..63a37b5 100644 --- a/app.py +++ b/app.py @@ -61,8 +61,7 @@ def dashboard(): all_topsets, selected_person_ids, selected_exercise_ids, min_date, max_date) if htmx: - return render_template('partials/page/dashboard.html', - model=people_and_exercise_rep_maxes, people=people, exercises=exercises, min_date=min_date, max_date=max_date, selected_person_ids=selected_person_ids, selected_exercise_ids=selected_exercise_ids, tags=tags), 200, {"HX-Trigger": "updatedPeople"} + return render_block(app.jinja_env, 'dashboard.html', 'content', model=people_and_exercise_rep_maxes, people=people, exercises=exercises, min_date=min_date, max_date=max_date, selected_person_ids=selected_person_ids, selected_exercise_ids=selected_exercise_ids, tags=tags) return render_template('dashboard.html', model=people_and_exercise_rep_maxes, people=people, exercises=exercises, min_date=min_date, max_date=max_date, selected_person_ids=selected_person_ids, selected_exercise_ids=selected_exercise_ids, tags=tags) @@ -134,8 +133,7 @@ def get_person(person_id): person['ExerciseGraphs'] = exercise_graph_view_models if htmx: - return render_template('partials/page/person.html', - person=person, selected_exercise_ids=active_exercise_ids, max_date=max_date, min_date=min_date, tags=tags, graph_axis=graph_axis), 200, {"HX-Trigger": "updatedPeople"} + return render_block(app.jinja_env, 'person.html', 'content', person=person, selected_exercise_ids=active_exercise_ids, max_date=max_date, min_date=min_date, tags=tags, graph_axis=graph_axis), 200, {"HX-Trigger": "updatedPeople"} return render_template('person.html', person=person, selected_exercise_ids=active_exercise_ids, max_date=max_date, min_date=min_date, tags=tags, graph_axis=graph_axis), 200, {"HX-Trigger": "updatedPeople"} @@ -161,9 +159,8 @@ def get_calendar(person_id): end_date = date_info['end_date'] if htmx: - return render_template('partials/page/calendar.html', - person=person, selected_date=selected_date, selected_view=selected_view, next_date=next_date, previous_date=previous_date, start_date=start_date, end_date=end_date) - return render_template('calendar.html', person=person, selected_date=selected_date, selected_view=selected_view, next_date=next_date, previous_date=previous_date, start_date=start_date, end_date=end_date) + return render_block(app.jinja_env, 'calendar.html', 'content', person=person, selected_date=selected_date, selected_view=selected_view, next_date=next_date, previous_date=previous_date, start_date=start_date, end_date=end_date, datetime=datetime, timedelta=timedelta, relativedelta=relativedelta) + return render_template('calendar.html', person=person, selected_date=selected_date, selected_view=selected_view, next_date=next_date, previous_date=previous_date, start_date=start_date, end_date=end_date, datetime=datetime, timedelta=timedelta, relativedelta=relativedelta) @ app.route("/person//workout//modal", methods=['GET']) @@ -387,6 +384,26 @@ def get_workout_note(person_id, workout_id): return render_template('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=workout['Note']) +@app.template_filter('list_to_string') +def list_to_string(list): + return [str(i) for i in list] + + +@app.template_filter('strftime') +def strftime(date, format="%b %d %Y"): + return date.strftime(format) + + +@app.template_filter('get_first_element_from_list_with_matching_attribute') +def get_first_element_from_list_with_matching_attribute(list, attribute, value): + if not list: + return None + for element in list: + if element[attribute] == value: + return element + return None + + @ app.context_processor def my_utility_processor(): diff --git a/templates/calendar.html b/templates/calendar.html index 727f896..9ee3f50 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -2,8 +2,190 @@ {% block content %} -{{ render_partial('partials/page/calendar.html', -person=person, selected_date=selected_date, selected_view=selected_view, next_date=next_date, -previous_date=previous_date, start_date=start_date, end_date=end_date) }} + + +
+
+
+
+ + +
+ + {% if selected_view == 'month' %} +

{{ selected_date | strftime('%B, %Y') }}

+ {% else %} +

{{ selected_date | strftime('%Y') }}

+ {% endif %} + {{ + person['PersonName']}} +
+ +
+ + +
+
+ + {% if selected_view == 'month' %} +
+
+ +
+ + Sun +
+
+ + Mon +
+
+ + Tue +
+
+ + Wed +
+
+ + Thu +
+
+ + Fri +
+
+ + Sat +
+
+ +
+ + {% for i in range((end_date-start_date).days + 1) %} + {% set date = start_date + timedelta(days=i) %} + {% set workout = person['Workouts'] | + get_first_element_from_list_with_matching_attribute( + 'StartDate', + date) %} +
+
+ {{ date.day }} +
+
+ {% if workout['TopSets']|length > 0 %} + {% for topset in workout['TopSets'] %} + + {% endfor %} + {% endif %} +
+
+ {% endfor %} + +
+
+ {% elif selected_view == 'year'%} +
+ +
+ {% for i in range(12) %} + {% set date = start_date + relativedelta(months=i) %} + {% set first_day_of_month = date.replace(day=1) %} + {% set last_day_of_month = date + relativedelta(day=31) %} + {% set (first_day, last_day) = first_and_last_visible_days_in_month(first_day_of_month, last_day_of_month) + %} +
+
{{ + first_day_of_month | strftime('%B %Y') }} +
+
+
+
S
+
M
+
T
+
W
+
T
+
F
+
S
+
+ +
+ {% for i in range((last_day-first_day).days + 1) %} + {% set day_date = first_day + timedelta(days=i) %} + {% set workout = person['Workouts'] | get_first_element_from_list_with_matching_attribute( + 'StartDate', + day_date) %} + {% set is_in_month = day_date.month == first_day_of_month.month%} +
+ {% if is_in_month %} + {{ day_date.day }} {% endif %}
+ {% endfor %} +
+
+
+ {% endfor %} + +
+
+ {% endif %} +
+ +{{ render_partial('partials/stats.html', stats=person['Stats']) }} + + {% endblock %} \ No newline at end of file diff --git a/templates/dashboard.html b/templates/dashboard.html index 7c80c08..938bdfe 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -2,8 +2,181 @@ {% block content %} -{{ render_partial('partials/page/dashboard.html', -model=model, people=people, exercises=exercises, min_date=min_date, max_date=max_date, -selected_person_ids=selected_person_ids, selected_exercise_ids=selected_exercise_ids, tags=tags) }} +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ {% with person_id=None, tags=tags %} + {% include 'partials/tags.html' %} + {% endwith %} +
+ + +{% if model['People']|length == 0 %} + +{% endif %} + +
+ + {% for p in model['People'] %} +
+ +
+
+

{{ p['PersonName'] }}

+ Current rep maxes +
+ +
+ + {% if p['NumberOfWorkouts'] == 0 %} + + {% endif %} + + {% for e in p['Exercises'] %} +
+
+
+
+

{{ e['ExerciseName'] }}

+ {% if e['RepMaxes']|length > 1 %} +
+ + {% endif %} + + + + + + + + + + {% for rm in e['RepMaxes'] %} + + + + + {% endfor %} + + +
+ Date + + Rep Max +
+ {{ rm['StartDate'] }} + + {{ rm['Repetitions'] }} x {{ rm['Weight'] }}kg +
+
+
+
+
+ {% endfor %} +
+ {% endfor %} + + +
+ +{{ render_partial('partials/stats.html', stats=model['Stats']) }} {% endblock %} \ No newline at end of file diff --git a/templates/partials/page/calendar.html b/templates/partials/page/calendar.html deleted file mode 100644 index 1508d31..0000000 --- a/templates/partials/page/calendar.html +++ /dev/null @@ -1,186 +0,0 @@ - - -
-
-
-
- - -
- - {% if selected_view == 'month' %} -

{{ strftime(selected_date, '%B, %Y') }}

- {% else %} -

{{ strftime(selected_date, '%Y') }}

- {% endif %} - {{ - person['PersonName']}} -
- -
- - -
-
- - {% if selected_view == 'month' %} -
-
- -
- - Sun -
-
- - Mon -
-
- - Tue -
-
- - Wed -
-
- - Thu -
-
- - Fri -
-
- - Sat -
-
- -
- - {% for i in range((end_date-start_date).days + 1) %} - {% set date = start_date + timedelta(days=i) %} - {% set workout = - get_first_element_from_list_with_matching_attribute(person['Workouts'], - 'StartDate', - date) %} -
-
- {{ date.day }} -
-
- {% if workout['TopSets']|length > 0 %} - {% for topset in workout['TopSets'] %} - - {% endfor %} - {% endif %} -
-
- {% endfor %} - -
-
- {% elif selected_view == 'year'%} -
- -
- {% for i in range(12) %} - {% set date = start_date + relativedelta(months=i) %} - {% set first_day_of_month = date.replace(day=1) %} - {% set last_day_of_month = date + relativedelta(day=31) %} - {% set (first_day, last_day) = first_and_last_visible_days_in_month(first_day_of_month, last_day_of_month) - %} -
-
{{ - strftime(first_day_of_month, '%B %Y') }} -
-
-
-
S
-
M
-
T
-
W
-
T
-
F
-
S
-
- -
- {% for i in range((last_day-first_day).days + 1) %} - {% set day_date = first_day + timedelta(days=i) %} - {% set workout = - get_first_element_from_list_with_matching_attribute(person['Workouts'], - 'StartDate', - day_date) %} - {% set is_in_month = day_date.month == first_day_of_month.month%} -
- {% if is_in_month %} - {{ day_date.day }} {% endif %}
- {% endfor %} -
-
-
- {% endfor %} - -
-
- {% endif %} -
- -{{ render_partial('partials/stats.html', stats=person['Stats']) }} - - \ No newline at end of file diff --git a/templates/partials/page/dashboard.html b/templates/partials/page/dashboard.html deleted file mode 100644 index 3df03c4..0000000 --- a/templates/partials/page/dashboard.html +++ /dev/null @@ -1,176 +0,0 @@ -
-
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
- {% with person_id=None, tags=tags %} - {% include 'partials/tags.html' %} - {% endwith %} -
- - -{% if model['People']|length == 0 %} - -{% endif %} - -
- - {% for p in model['People'] %} -
- -
-
-

{{ p['PersonName'] }}

- Current rep maxes -
- -
- - {% if p['NumberOfWorkouts'] == 0 %} - - {% endif %} - - {% for e in p['Exercises'] %} -
-
-
-
-

{{ e['ExerciseName'] }}

- {% if e['RepMaxes']|length > 1 %} -
- - {% endif %} - - - - - - - - - - {% for rm in e['RepMaxes'] %} - - - - - {% endfor %} - - -
- Date - - Rep Max -
- {{ rm['StartDate'] }} - - {{ rm['Repetitions'] }} x {{ rm['Weight'] }}kg -
-
-
-
-
- {% endfor %} -
- {% endfor %} - - -
- -{{ render_partial('partials/stats.html', stats=model['Stats']) }} \ No newline at end of file diff --git a/templates/partials/page/person.html b/templates/partials/page/person.html deleted file mode 100644 index 5702302..0000000 --- a/templates/partials/page/person.html +++ /dev/null @@ -1,262 +0,0 @@ - - -
-
- -
-
-

{{ person['PersonName'] }}

- List of workouts -
-
-
- - -
-
-
- - -
- {% set exercise_list = person['FilteredExercises'] %} - -
- -
-
-
- - -
- -
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
-
- - -
- -
-
- - {% with person_id=person['PersonId'], tags=tags %} - {% include 'partials/tags.html' %} - {% endwith %} - -
-
-
-
- - {% 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'] }} -
- {{ strftime(w['StartDate'], "%b %d %Y") }} - - {% 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 %} -
- {% endif %} - - {% if person['Workouts']|length == 0 %} - - {% endif %} - -
-
-
-
- -
-
- -{% if graph_axis %} -
- {% for exercise_graph in person['ExerciseGraphs'] %} -
-
-
- {{ - exercise_graph['ExerciseName'] }} -
-
- -
-
- {% endfor %} -
-{% 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 c11588d..cd2ce49 100644 --- a/templates/person.html +++ b/templates/person.html @@ -2,8 +2,267 @@ {% block content %} -{{ render_partial('partials/page/person.html', -person=person, selected_exercise_ids=selected_exercise_ids, max_date=max_date, -min_date=min_date, tags=tags, graph_axis=graph_axis) }} + + +
+
+ +
+
+

{{ person['PersonName'] }}

+ List of workouts +
+
+
+ + +
+
+
+ + +
+ {% set exercise_list = person['FilteredExercises'] %} + +
+ +
+
+
+ + +
+ +
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+ + +
+ +
+
+ + {% with person_id=person['PersonId'], tags=tags %} + {% include 'partials/tags.html' %} + {% endwith %} + +
+
+
+
+ + {% 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'] | strftime("%b %d %Y") }} + + {% set topset_exercise = w['TopSets'] | + get_first_element_from_list_with_matching_attribute('ExerciseId', + e['ExerciseId']) %} + {% if topset_exercise %} + {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg + {% endif %} +
+ {% endif %} + + {% if person['Workouts']|length == 0 %} + + {% endif %} + +
+
+
+
+ +
+
+ +{% if graph_axis %} +
+ {% for exercise_graph in person['ExerciseGraphs'] %} +
+
+
+ {{ + exercise_graph['ExerciseName'] }} +
+
+ +
+
+ {% endfor %} +
+{% endif %} + +{{ render_partial('partials/stats.html', stats=person['Stats']) }} + + {% endblock %} \ No newline at end of file