Track dates of English school holidays

Fixes #168
This commit is contained in:
Edward Betts 2026-02-21 18:05:19 +00:00
parent 7a50ea6016
commit 61e17d9c96
10 changed files with 416 additions and 4 deletions

View file

@ -32,6 +32,7 @@ import agenda.trip
import agenda.trip_schengen
import agenda.utils
from agenda import ical, calendar, format_list_with_ampersand, travel, uk_tz
from agenda.event import Event
from agenda.types import StrDict, Trip
app = flask.Flask(__name__)
@ -588,6 +589,33 @@ def get_trip_list() -> list[Trip]:
return agenda.trip.get_trip_list(route_distances)
def trip_school_holiday_map(trips: list[Trip]) -> dict[str, list[Event]]:
"""Map trip-start ISO date to overlapping UK school holidays."""
if not trips:
return {}
starts = [trip.start for trip in trips]
ends = [trip.end or trip.start for trip in trips]
school_holidays = agenda.holidays.get_school_holidays(
min(starts),
max(ends),
app.config["DATA_DIR"],
)
result: dict[str, list[Event]] = {}
for trip in trips:
trip_end = trip.end or trip.start
overlaps = [
school_holiday
for school_holiday in school_holidays
if school_holiday.as_date <= trip_end
and school_holiday.end_as_date >= trip.start
]
result[trip.start.isoformat()] = overlaps
return result
@app.route("/trip/past")
def trip_past_list() -> str:
"""Page showing a list of past trips."""
@ -599,6 +627,7 @@ def trip_past_list() -> str:
"trip/list.html",
heading="Past trips",
trips=reversed(past),
trip_school_holiday_map=trip_school_holiday_map(past),
coordinates=coordinates,
routes=routes,
today=today,
@ -643,10 +672,13 @@ def trip_future_list() -> str:
coordinates, routes = agenda.trip.get_coordinates_and_routes(current + future)
shown = current + future
return flask.render_template(
"trip/list.html",
heading="Future trips",
trips=current + future,
trips=shown,
trip_school_holiday_map=trip_school_holiday_map(shown),
coordinates=coordinates,
routes=routes,
today=today,
@ -726,6 +758,7 @@ def trip_page(start: str) -> str:
get_country=agenda.get_country,
format_list_with_ampersand=format_list_with_ampersand,
holidays=agenda.holidays.get_trip_holidays(trip),
school_holidays=agenda.holidays.get_trip_school_holidays(trip),
human_readable_delta=agenda.utils.human_readable_delta,
)
@ -811,11 +844,19 @@ def holiday_list() -> str:
data_dir = app.config["DATA_DIR"]
next_year = today + timedelta(days=1 * 365)
items = agenda.holidays.get_all(today - timedelta(days=2), next_year, data_dir)
school_holidays = agenda.holidays.get_school_holidays(
today - timedelta(days=2), next_year, data_dir
)
items.sort(key=lambda item: (item.date, item.country))
school_holidays.sort(key=lambda item: (item.as_date, item.end_as_date))
return flask.render_template(
"holiday_list.html", items=items, get_country=agenda.get_country, today=today
"holiday_list.html",
items=items,
school_holidays=school_holidays,
get_country=agenda.get_country,
today=today,
)