Show country names and flags on accommodation page

This commit is contained in:
Edward Betts 2024-01-03 11:33:24 +00:00
parent 9800030201
commit fd46f0a405
2 changed files with 19 additions and 2 deletions

View file

@ -1,9 +1,10 @@
{% extends "base.html" %}
{% block style %}
{% set column_count = 7 %}
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(6, auto);
grid-template-columns: repeat({{ column_count }}, auto);
gap: 10px;
justify-content: start;
}
@ -13,18 +14,28 @@
}
.heading {
grid-column: 1 / 7; /* Spans from the 1st line to the 7th line */
grid-column: 1 / {{ column_count + 1 }}; /* Spans from the 1st line to the 7th line */
}
</style>
{% endblock %}
{% macro row(item, badge) %}
{% set country = get_country(item.country) %}
<div class="grid-item text-end">{{ item.from.strftime("%a, %d %b %Y") }}</div>
<div class="grid-item text-end">{{ item.to.strftime("%a, %d %b") }}</div>
<div class="grid-item text-end">{{ (item.to.date() - item.from.date()).days }}</div>
<div class="grid-item">{{ item.name }}</div>
<div class="grid-item">{{ item.operator }}</div>
<div class="grid-item">{{ item.location }}</div>
<div class="grid-item">
{% if country %}
{{ country.flag }} {{ country.name }}
{% else %}
<span class="text-bg-danger p-2">
country code <strong>{{ item.country }}</strong> not found
</span>
{% endif %}
</div>
{% endmacro %}
{% macro section(heading, item_list, badge) %}

View file

@ -7,9 +7,11 @@ import operator
import os.path
import sys
import traceback
import typing
from datetime import date, datetime
import flask
import pycountry
import werkzeug
import werkzeug.debug.tbtools
import yaml
@ -140,11 +142,15 @@ def accommodation_list() -> str:
if stay["country"] != "gb"
)
def get_country(alpha_2: str) -> str | None:
return typing.cast(str | None, pycountry.countries.get(alpha_2=alpha_2.upper()))
return flask.render_template(
"accommodation.html",
items=items,
total_nights_2024=total_nights_2024,
nights_abroad_2024=nights_abroad_2024,
get_country=get_country,
)