From ab839565583865dd13dc399781b37b2c4b73c976 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 3 Nov 2023 15:22:53 +0000 Subject: [PATCH] Improve calendar event display --- agenda/__init__.py | 32 +++++++++++++++++++++++++++++++- agenda/types.py | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/agenda/__init__.py b/agenda/__init__.py index e5ee290..2923ecb 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -657,11 +657,41 @@ def build_events_for_calendar(events: list[Event]) -> list[dict[str, typing.Any] """Build list of events for FullCalendar.""" items: list[dict[str, typing.Any]] = [] + one_day = timedelta(days=1) + for e in events: + if e.name == "accommodation": + assert e.title and e.end_date + item = { + "allDay": True, + "title": e.display_title, + "start": e.as_date.isoformat(), + "end": (e.end_as_date + one_day).isoformat(), + "url": e.url, + } + items.append(item) + + item = { + "allDay": False, + "title": "checkin: " + e.title, + "start": e.date.isoformat(), + "url": e.url, + } + items.append(item) + item = { + "allDay": False, + "title": "checkout: " + e.title, + "start": e.end_date.isoformat(), + "url": e.url, + } + items.append(item) + + continue + if e.has_time: end = e.end_date or e.date + timedelta(hours=1) else: - end = (e.end_as_date if e.end_date else e.as_date) + timedelta(days=1) + end = (e.end_as_date if e.end_date else e.as_date) + one_day item = { "allDay": not e.has_time, "title": e.display_title, diff --git a/agenda/types.py b/agenda/types.py index e209fea..1a99948 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -88,4 +88,4 @@ class Event: @property def display_title(self) -> str: """Name for display.""" - return self.name + ": " + self.title if self.title else self.name + return self.title or self.name