Next trip and previous trip links on trip pages

Closes: #110
This commit is contained in:
Edward Betts 2024-01-14 12:29:39 +00:00
parent 36b5d38274
commit fbee775f5b
3 changed files with 19 additions and 3 deletions

View file

@ -191,10 +191,15 @@ def trip_list() -> str:
@app.route("/trip/<start>")
def trip_page(start: str) -> str:
"""Individual trip page."""
trip_list = agenda.trip.build_trip_list()
trip_iter = iter(agenda.trip.build_trip_list())
today = date.today()
trip = next((trip for trip in trip_list if trip.start.isoformat() == start), None)
prev_trip = None
for trip in trip_iter:
if trip.start.isoformat() == start:
break
prev_trip = trip
next_trip = next(trip_iter, None)
if not trip:
flask.abort(404)
@ -208,6 +213,8 @@ def trip_page(start: str) -> str:
return flask.render_template(
"trip_page.html",
trip=trip,
prev_trip=prev_trip,
next_trip=next_trip,
today=today,
coordinates=coordinates,
routes=routes,