From aed610d8b694b28dc6ccdac2055a488d9e5079d0 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 3 Dec 2022 16:57:35 +1100 Subject: [PATCH] Make calendar month view default when viewing a persons workout and display workouts for month view (year view remaining) --- app.py | 25 ++- templates/calendar.html | 2 +- templates/partials/page/calendar.html | 308 ++------------------------ templates/partials/people_link.html | 2 +- 4 files changed, 43 insertions(+), 294 deletions(-) diff --git a/app.py b/app.py index 3b4ff17..4246f62 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ from datetime import datetime, date, timedelta +import calendar import os from flask import Flask, render_template, redirect, request, url_for import jinja_partials @@ -31,7 +32,7 @@ def get_person_list(): return render_template('partials/people_link.html', people=people) -@ app.route("/person/") +@ app.route("/person//workout/list", methods=['GET']) @ validate_person def get_person(person_id): person = db.get_person(person_id) @@ -70,15 +71,31 @@ def get_calendar(person_id): 'date'), '%Y-%m-%d') or date.today() selected_view = request.args.get('view') or 'month' + if selected_view == 'all': + return redirect(url_for('get_person', person_id=person_id)) + next_date = selected_date + (timedelta( 365/12) if selected_view == 'month' else timedelta(365)) previous_date = selected_date + (timedelta( -365/12) if selected_view == 'month' else timedelta(-365)) + first_date_of_view = selected_date.replace( + day=1) if selected_view == 'month' else selected_date.replace(month=1, day=1) + last_date_of_view = first_date_of_view + \ + (timedelta(365/12) if selected_view == 'month' else timedelta(365)) + + start = dict([(6, 0), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]) + start_date = first_date_of_view - \ + timedelta(days=start[first_date_of_view.weekday()]) + + end = dict([(6, 6), (0, 5), (1, 4), (2, 3), (3, 2), (4, 1), (5, 0)]) + end_date = last_date_of_view + \ + timedelta(days=end[last_date_of_view.weekday()]) + 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) - return render_template('calendar.html', person=person, selected_date=selected_date, selected_view=selected_view, next_date=next_date, previous_date=previous_date) + 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) @ app.route("/person//workout", methods=['POST']) @@ -282,7 +299,7 @@ def my_utility_processor(): def strftime(date, format="%b %d %Y"): return date.strftime(format) - 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, strftime=strftime) + 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, strftime=strftime, datetime=datetime, timedelta=timedelta) if __name__ == '__main__': diff --git a/templates/calendar.html b/templates/calendar.html index 134c257..727f896 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -4,6 +4,6 @@ {{ render_partial('partials/page/calendar.html', person=person, selected_date=selected_date, selected_view=selected_view, next_date=next_date, -previous_date=previous_date) }} +previous_date=previous_date, start_date=start_date, end_date=end_date) }} {% endblock %} \ No newline at end of file diff --git a/templates/partials/page/calendar.html b/templates/partials/page/calendar.html index a66f7dd..f302426 100644 --- a/templates/partials/page/calendar.html +++ b/templates/partials/page/calendar.html @@ -35,6 +35,7 @@ hx-vals='{"date": "{{ selected_date }}"}' hx-push-url="true"> + @@ -74,301 +75,32 @@
-
+ {% 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) %} +
- 1 + {{ date.day }}
+ {% if workout %} + {% for topset in workout['TopSets'] %} - + {% endfor %} + {% endif %}
- -
-
- 2 -
-
- - -
-
- -
-
- 3 -
-
-
- -
-
- 4 -
-
-
- -
-
- 6 -
-
-
- -
-
- 7 -
-
- - -
-
- -
-
- 8 -
-
-
- -
-
- 9 -
-
-
- -
-
- 10 -
-
-
- -
-
- 12 -
-
- - -
-
- -
-
- 13 -
-
-
- -
-
- 14 -
-
-
- -
-
- 15 -
-
-
- -
-
- 16 -
-
-
- -
-
- 16 -
-
- - -
-
- -
-
- 17 -
-
-
- -
-
- 18 -
-
-
- -
-
- 19 -
-
-
- -
-
- 20 -
-
-
- -
-
- 21 -
-
-
- -
-
- 22 -
-
-
- -
-
- 23 -
-
-
- -
-
- 24 -
-
-
- -
-
- 25 -
-
-
- -
-
- 26 -
-
-
- -
-
- 27 -
-
-
- -
-
- 28 -
-
-
- -
-
- 29 -
-
-
- -
-
- 30 -
-
-
- -
-
- 31 -
-
-
- -
-
- 1 -
-
-
- -
-
- 2 -
-
-
- -
-
- 3 -
-
-
- -
-
- 4 -
-
-
- -
-
- 5 -
-
-
+ {% endfor %}
diff --git a/templates/partials/people_link.html b/templates/partials/people_link.html index 959b600..f199c33 100644 --- a/templates/partials/people_link.html +++ b/templates/partials/people_link.html @@ -1,6 +1,6 @@ {% for p in people %}
  • -