Add option for unpublished trips

This commit is contained in:
Edward Betts 2024-03-26 14:54:02 +00:00
parent e3cae68d2f
commit d690442f0f
3 changed files with 30 additions and 4 deletions

View file

@ -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())]

View file

@ -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
]

View file

@ -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/<start>")
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"]