Show current trip on home page

This commit is contained in:
Edward Betts 2024-08-11 12:50:58 +02:00
parent 6e9604e4c1
commit 259642ff52
2 changed files with 28 additions and 0 deletions

View file

@ -68,6 +68,19 @@ def exception_handler(e: werkzeug.exceptions.InternalServerError) -> tuple[str,
)
def get_current_trip(today: date) -> Trip | None:
"""Get current trip."""
trip_list = get_trip_list(route_distances=None)
current = [
item
for item in trip_list
if item.start <= today and (item.end or item.start) >= today
]
assert len(current) < 2
return current[0] if current else None
@app.route("/")
async def index() -> str:
"""Index page."""
@ -87,6 +100,7 @@ async def index() -> str:
"event_list.html",
today=now.date(),
events=events,
current_trip=get_current_trip(now.date()),
fullcalendar_events=calendar.build_events(events),
start_event_list=date.today() - timedelta(days=1),
end_event_list=date.today() + timedelta(days=365 * 2),