More code re-use

This commit is contained in:
Edward Betts 2024-04-17 14:33:23 +01:00
parent d28e172a8c
commit 32e07d4ce4

View file

@ -232,18 +232,24 @@ def accommodation_list() -> str:
)
@app.route("/trip")
def trip_list() -> str:
"""Page showing a list of trips."""
route_distances = agenda.travel.load_route_distances(app.config["DATA_DIR"])
trip_list = [
def get_trip_list(
route_distances: agenda.travel.RouteDistances | None = None,
) -> list[Trip]:
"""Get list of trips respecting current authentication status."""
return [
trip
for trip in agenda.trip.build_trip_list(route_distances=route_distances)
if flask.g.user.is_authenticated or not trip.private
]
@app.route("/trip")
def trip_list() -> str:
"""Page showing a list of trips."""
route_distances = agenda.travel.load_route_distances(app.config["DATA_DIR"])
trip_list = get_trip_list(route_distances)
today = date.today()
current = [
item
for item in trip_list
@ -274,12 +280,7 @@ def trip_list() -> str:
@app.route("/trip/text")
def trip_list_text() -> str:
"""Page showing a list of trips."""
trip_list = [
trip
for trip in agenda.trip.build_trip_list()
if flask.g.user.is_authenticated or not trip.private
]
trip_list = get_trip_list()
today = date.today()
future = [item for item in trip_list if item.start > today]
@ -325,15 +326,6 @@ def human_readable_delta(future_date: date) -> str | None:
return " ".join(parts) if parts else None
def get_trip_list(route_distances: agenda.travel.RouteDistances) -> list[Trip]:
"""Get list of trips respecting current authentication status."""
return [
trip
for trip in agenda.trip.build_trip_list(route_distances=route_distances)
if flask.g.user.is_authenticated or not trip.private
]
def get_prev_current_and_next_trip(
start: str, trip_list: list[Trip]
) -> tuple[Trip | None, Trip | None, Trip | None]: