@classmethod
def all(cls, db_conn: DatabaseConnection,
- date_range: tuple[str, str] = ('', '')):
+ date_range: tuple[str, str] = ('', ''), fill_gaps: bool = False):
"""Return list of Days in database within date_range."""
def date_from_range_str(date_str: str, default: str):
if date_str == '':
for row in db_conn.exec(sql, (start_date, end_date)):
days += [cls.from_table_row(row)]
days.sort()
+ if fill_gaps and len(days) > 1:
+ gapless_days = []
+ for i, day in enumerate(days):
+ gapless_days += [day]
+ if i < len(days) - 1:
+ while day.next_date != days[i+1].date:
+ day = Day(day.next_date)
+ gapless_days += [day]
+ days = gapless_days
return days
@classmethod
def do_GET_calendar(self, conn: DatabaseConnection, start: str, end: str):
"""Show Days."""
+ days = Day.all(conn, date_range=(start, end), fill_gaps=True)
return self.server.jinja.get_template('calendar.html').render(
- days=Day.all(conn, date_range=(start, end)),
- start=start, end=end)
+ days=days, start=start, end=end)
def do_GET_day(self, conn: DatabaseConnection, date: str):
"""Show single Day."""
[day1, day2])
self.assertEqual(Day.all(self.db_conn, ('2024-01-03', '2024-01-01')),
[])
+ day4 = Day('2024-01-04')
+ day5 = Day('2024-01-05')
+ day6 = Day('2024-01-06')
+ day6.save(self.db_conn)
+ self.assertEqual(Day.all(self.db_conn, ('2024-01-02', '2024-01-07'),
+ fill_gaps=True),
+ [day2, day3, day4, day5, day6])
today = Day(todays_date())
today.save(self.db_conn)
self.assertEqual(Day.all(self.db_conn, ('today', 'today')), [today])