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 get_trip_list(
def trip_list() -> str: route_distances: agenda.travel.RouteDistances | None = None,
"""Page showing a list of trips.""" ) -> list[Trip]:
route_distances = agenda.travel.load_route_distances(app.config["DATA_DIR"]) """Get list of trips respecting current authentication status."""
return [
trip_list = [
trip trip
for trip in agenda.trip.build_trip_list(route_distances=route_distances) for trip in agenda.trip.build_trip_list(route_distances=route_distances)
if flask.g.user.is_authenticated or not trip.private 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() today = date.today()
current = [ current = [
item item
for item in trip_list for item in trip_list
@ -274,12 +280,7 @@ def trip_list() -> str:
@app.route("/trip/text") @app.route("/trip/text")
def trip_list_text() -> str: def trip_list_text() -> str:
"""Page showing a list of trips.""" """Page showing a list of trips."""
trip_list = [ trip_list = get_trip_list()
trip
for trip in agenda.trip.build_trip_list()
if flask.g.user.is_authenticated or not trip.private
]
today = date.today() today = date.today()
future = [item for item in trip_list if item.start > 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 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( def get_prev_current_and_next_trip(
start: str, trip_list: list[Trip] start: str, trip_list: list[Trip]
) -> tuple[Trip | None, Trip | None, Trip | None]: ) -> tuple[Trip | None, Trip | None, Trip | None]: