Change logic for calendar month view so it always renders the same number of weeks (Sunday-Saturday) regardless of length of month, & what day of the week it started. This resolves the rerender when you switch between months with varying number of weeks
This commit is contained in:
11
utils.py
11
utils.py
@@ -222,13 +222,12 @@ def get_date_info(input_date, selected_view):
|
|||||||
|
|
||||||
# Business logic, should move above to a separate function
|
# Business logic, should move above to a separate function
|
||||||
if selected_view == 'month':
|
if selected_view == 'month':
|
||||||
start = dict([(6, 0), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)])
|
# Step 1: Find the first Sunday before or on the first day of the month
|
||||||
start_date = first_day_of_month - \
|
days_to_subtract = (first_day_of_month.weekday() + 1) % 7
|
||||||
timedelta(days=start[first_day_of_month.weekday()])
|
start_date = first_day_of_month - timedelta(days=days_to_subtract)
|
||||||
|
|
||||||
end = dict([(6, 6), (0, 5), (1, 4), (2, 3), (3, 2), (4, 1), (5, 0)])
|
# Step 2: Calculate the last day to display, based on the number of weeks
|
||||||
end_date = last_day_of_month + \
|
end_date = start_date + timedelta(days=6 * 7 - 1)
|
||||||
timedelta(days=end[last_day_of_month.weekday()])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'next_date': next_month,
|
'next_date': next_month,
|
||||||
|
|||||||
Reference in New Issue
Block a user