From 5fdfd9d53350e7010e81cac2e524102b071b947e Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 28 Feb 2024 15:49:48 +0000 Subject: [PATCH] Generate trip titles from railway station names --- agenda/types.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/agenda/types.py b/agenda/types.py index 608a6fb..cb4f505 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -34,13 +34,21 @@ class Trip: @property def title(self) -> str: """Trip title.""" - return ( - format_list_with_ampersand( - [conf["name"] for conf in self.conferences] - + [event["title"] for event in self.events] - ) - or "[unnamed trip]" - ) + titles: list[str] = [conf["name"] for conf in self.conferences] + [ + event["title"] for event in self.events + ] + if not titles: + for travel in self.travel: + if travel["depart"] and travel["depart"].date() != self.start: + place = travel["from"] + if place not in titles: + titles.append(place) + if travel["depart"] and travel["depart"].date() != self.end: + place = travel["to"] + if place not in titles: + titles.append(place) + + return format_list_with_ampersand(titles) or "[unnamed trip]" @property def end(self) -> datetime.date | None: