[Bugfix] Rework month padding and event fetching routines
Month padding (ie. adding the days of previous/next months) is now working as expected. Fetching multi-day events now also displays events correctly.
This commit is contained in:
parent
8eb52ff7f4
commit
6078e6171f
@ -83,17 +83,23 @@ class GregorianCalendar(CalendarSystem):
|
||||
def days(self):
|
||||
day_list = []
|
||||
|
||||
start_day = self.timestamp.replace(day=1)
|
||||
month_first = self.timestamp.replace(day=1)
|
||||
|
||||
while start_day.weekday() > self.START_DAY:
|
||||
start_day -= timedelta(days=1)
|
||||
if self.timestamp.month == 12:
|
||||
month_last = month_first.replace(day=31)
|
||||
else:
|
||||
month_last = month_first.replace(month=month_first.month + 1) - timedelta(days=1)
|
||||
|
||||
day_list.append(start_day)
|
||||
current_day = start_day
|
||||
pad_before = (7 - self.START_DAY + month_first.weekday()) % 7
|
||||
pad_after = (6 - month_last.weekday() + self.START_DAY) % 7
|
||||
|
||||
while current_day.weekday() < self.END_DAY and current_day.month <= self.timestamp.month:
|
||||
current_day += timedelta(days=1)
|
||||
day_list.append(current_day)
|
||||
first_display = month_first - timedelta(days=pad_before)
|
||||
last_display = month_last + timedelta(days=pad_after)
|
||||
current = first_display
|
||||
|
||||
while current <= last_display:
|
||||
day_list.append(current)
|
||||
current += timedelta(days=1)
|
||||
|
||||
return day_list
|
||||
|
||||
@ -212,10 +218,8 @@ class GregorianCalendar(CalendarSystem):
|
||||
start_timestamp = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
end_timestamp = start_timestamp + timedelta(days=1)
|
||||
|
||||
events = events.filter(((Event.start_time >= start_timestamp) &
|
||||
(Event.start_time < end_timestamp)) |
|
||||
((Event.end_time >= start_timestamp) &
|
||||
(Event.end_time < end_timestamp))) \
|
||||
events = events.filter((Event.start_time <= end_timestamp) &
|
||||
(Event.end_time >= start_timestamp)) \
|
||||
.order_by('start_time', 'end_time')
|
||||
|
||||
if user is None:
|
||||
|
Loading…
Reference in New Issue
Block a user