From d690442f0fb3ac212a57758d7cd5fd6a4777ad7b Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 26 Mar 2024 14:54:02 +0000 Subject: [PATCH] Add option for unpublished trips --- agenda/trip.py | 9 ++++++++- agenda/types.py | 4 ++++ web_view.py | 21 ++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/agenda/trip.py b/agenda/trip.py index b303a6a..06fbf2a 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -67,6 +67,10 @@ def build_trip_list(data_dir: str | None = None) -> list[Trip]: if data_dir is None: data_dir = flask.current_app.config["PERSONAL_DATA"] + yaml_trip_list = travel.parse_yaml("trips", data_dir) + + yaml_trip_lookup = {item["trip"]: item for item in yaml_trip_list} + travel_items = sorted( load_flights(data_dir) + load_trains(data_dir), key=depart_datetime ) @@ -84,7 +88,10 @@ def build_trip_list(data_dir: str | None = None) -> list[Trip]: if not (start := item.get("trip")): continue if start not in trips: - trips[start] = Trip(start=start) + from_yaml = yaml_trip_lookup.get(start, {}) + trips[start] = Trip( + start=start, **{k: v for k, v in from_yaml.items() if k != "trip"} + ) getattr(trips[start], key).append(item) return [trip for _, trip in sorted(trips.items())] diff --git a/agenda/types.py b/agenda/types.py index 4a569d6..ed59d86 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -30,10 +30,14 @@ class Trip: accommodation: list[StrDict] = field(default_factory=list) conferences: list[StrDict] = field(default_factory=list) events: list[StrDict] = field(default_factory=list) + name: str | None = None + private: bool = False @property def title(self) -> str: """Trip title.""" + if self.name: + return self.name titles: list[str] = [conf["name"] for conf in self.conferences] + [ event["title"] for event in self.events ] diff --git a/web_view.py b/web_view.py index 468e58f..33be6f7 100755 --- a/web_view.py +++ b/web_view.py @@ -209,7 +209,11 @@ def accommodation_list() -> str: @app.route("/trip") def trip_list() -> str: """Page showing a list of trips.""" - trip_list = agenda.trip.build_trip_list() + trip_list = [ + trip + for trip in agenda.trip.build_trip_list() + if flask.g.user.is_authenticated or not trip.private + ] today = date.today() current = [ @@ -242,7 +246,11 @@ def trip_list() -> str: @app.route("/trip/text") def trip_list_text() -> str: """Page showing a list of trips.""" - trip_list = agenda.trip.build_trip_list() + trip_list = [ + trip + for trip in agenda.trip.build_trip_list() + if flask.g.user.is_authenticated or not trip.private + ] today = date.today() future = [item for item in trip_list if item.start > today] @@ -292,7 +300,14 @@ def human_readable_delta(future_date: date) -> str | None: @app.route("/trip/") def trip_page(start: str) -> str: """Individual trip page.""" - trip_iter = iter(agenda.trip.build_trip_list()) + + trip_list = [ + trip + for trip in agenda.trip.build_trip_list() + if flask.g.user.is_authenticated or not trip.private + ] + + trip_iter = iter(trip_list) today = date.today() data_dir = flask.current_app.config["PERSONAL_DATA"]