From 32e07d4ce4e4ef510b5e13b95410edd07b0335c2 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 17 Apr 2024 14:33:23 +0100 Subject: [PATCH] More code re-use --- web_view.py | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/web_view.py b/web_view.py index fd61549..4cb2c28 100755 --- a/web_view.py +++ b/web_view.py @@ -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]: