Fix for bug where when on the first of the month(eg today 1/5/23) and your on month view for a person then clicking previous date(Next to eg. May, 2023) would take you to March, also did a slight refactor

This commit is contained in:
Peter Stockings
2023-05-01 21:20:00 +10:00
parent bdf1680b19
commit 6474741f1e
2 changed files with 71 additions and 21 deletions

28
app.py
View File

@@ -5,7 +5,7 @@ from flask import Flask, render_template, redirect, request, url_for
import jinja_partials
from decorators import validate_person, validate_topset, validate_workout
from db import DataBase
from utils import flatten, get_people_and_exercise_rep_maxes, convert_str_to_date, get_earliest_and_latest_workout_date, filter_workout_topsets, get_exercise_ids_from_workouts, first_and_last_visible_days_in_month
from utils import flatten, get_date_info, get_people_and_exercise_rep_maxes, convert_str_to_date, get_earliest_and_latest_workout_date, filter_workout_topsets, get_exercise_ids_from_workouts, first_and_last_visible_days_in_month
from flask_htmx import HTMX
import minify_html
from urllib.parse import urlparse, unquote, quote
@@ -150,27 +150,13 @@ def get_calendar(person_id):
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))
# selected_view = month | year | all
date_info = get_date_info(selected_date, selected_view)
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 selected_view == 'year':
start_date = first_date_of_view
end_date = last_date_of_view
next_date = date_info['next_date']
previous_date = date_info['previous_date']
start_date = date_info['start_date']
end_date = date_info['end_date']
if htmx:
return render_template('partials/page/calendar.html',