Show holidays in visited countries on trip page

Closes: #112
This commit is contained in:
Edward Betts 2024-01-16 18:08:50 +00:00
parent 4b6f4231b7
commit 44bf744361
2 changed files with 33 additions and 0 deletions

View file

@ -72,6 +72,25 @@
{% for item in trip.travel %} {{ row[item.type](item) }} {% endfor %}
</div>
<div class="mt-3">
<h4>Holidays</h4>
<table class="table table-hover w-auto">
{% for item in holidays %}
{% set country = get_country(item.country) %}
<tr>
{% if loop.first or item.date != loop.previtem.date %}
<td class="text-end">{{ display_date(item.date) }}</td>
{% else %}
<td></td>
{% endif %}
<td>{{ country.flag }} {{ country.name }}</td>
<td>{{ item.display_name }}</td>
</tr>
{% endfor %}
</table>
</div>
<p>
{% if prev_trip %}
previous: {{ trip_link(prev_trip) }} ({{ (trip.start - prev_trip.end).days }} days)

View file

@ -253,6 +253,19 @@ def trip_page(start: str) -> str:
if "geojson_filename" in route:
route["geojson"] = agenda.trip.read_geojson(route.pop("geojson_filename"))
if trip.end:
countries = {c.alpha_2 for c in trip.countries}
holidays = [
hol
for hol in agenda.holidays.get_all(
trip.start, trip.end, app.config["DATA_DIR"]
)
if hol.country.upper() in countries
]
holidays.sort(key=lambda item: (item.date, item.country))
else:
holidays = []
return flask.render_template(
"trip_page.html",
trip=trip,
@ -263,6 +276,7 @@ def trip_page(start: str) -> str:
routes=routes,
get_country=agenda.get_country,
format_list_with_ampersand=format_list_with_ampersand,
holidays=holidays,
)