Show country names and flags on conference page

This commit is contained in:
Edward Betts 2024-01-03 15:52:24 +00:00
parent fd46f0a405
commit 17036d849f
3 changed files with 29 additions and 6 deletions

View file

@ -18,6 +18,7 @@ class Conference:
location: str location: str
start: date | datetime start: date | datetime
end: date | datetime end: date | datetime
country: str | None = None
venue: str | None = None venue: str | None = None
address: str | None = None address: str | None = None
url: str | None = None url: str | None = None

View file

@ -1,10 +1,11 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block style %} {% block style %}
{% set column_count = 7 %}
<style> <style>
.grid-container { .grid-container {
display: grid; display: grid;
grid-template-columns: repeat(6, auto); /* 7 columns for each piece of information */ grid-template-columns: repeat({{ column_count }}, auto); /* 7 columns for each piece of information */
gap: 10px; gap: 10px;
justify-content: start; justify-content: start;
} }
@ -14,12 +15,13 @@
} }
.heading { .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> </style>
{% endblock %} {% endblock %}
{% macro row(item, badge) %} {% macro row(item, badge) %}
{% set country = get_country(item.country) if item.country else None %}
<div class="grid-item text-end">{{ item.start.strftime("%a, %d %b %Y") }}</div> <div class="grid-item text-end">{{ item.start.strftime("%a, %d %b %Y") }}</div>
<div class="grid-item text-end">{{ item.end.strftime("%a, %d %b") }}</div> <div class="grid-item text-end">{{ item.end.strftime("%a, %d %b") }}</div>
<div class="grid-item">{{ item.name }} <div class="grid-item">{{ item.name }}
@ -37,6 +39,17 @@
</div> </div>
<div class="grid-item">{{ item.topic }}</div> <div class="grid-item">{{ item.topic }}</div>
<div class="grid-item">{{ item.location }}</div> <div class="grid-item">{{ item.location }}</div>
<div class="grid-item">
{% if country %}
{{ country.flag }} {{ country.name }}
{% elif item.online %}
💻 Online
{% else %}
<span class="text-bg-danger p-2">
country code <strong>{{ item.country }}</strong> not found
</span>
{% endif %}
</div>
<div class="grid-item"><a href="{{ item.url }}">{{ item.url }}</a></div> <div class="grid-item"><a href="{{ item.url }}">{{ item.url }}</a></div>
{% endmacro %} {% endmacro %}

View file

@ -98,6 +98,13 @@ def as_date(d: date | datetime) -> date:
return d.date() if isinstance(d, datetime) else d return d.date() if isinstance(d, datetime) else d
def get_country(alpha_2: str) -> str | None:
"""Lookup country by alpha-2 country code."""
if not alpha_2:
return None
return typing.cast(str, pycountry.countries.get(alpha_2=alpha_2.upper()))
@app.route("/conference") @app.route("/conference")
def conference_list() -> str: def conference_list() -> str:
"""Page showing a list of conferences.""" """Page showing a list of conferences."""
@ -121,7 +128,12 @@ def conference_list() -> str:
future = [conf for conf in item_list if conf["start_date"] > today] future = [conf for conf in item_list if conf["start_date"] > today]
return flask.render_template( return flask.render_template(
"conference_list.html", current=current, past=past, future=future, today=today "conference_list.html",
current=current,
past=past,
future=future,
today=today,
get_country=get_country,
) )
@ -142,9 +154,6 @@ def accommodation_list() -> str:
if stay["country"] != "gb" 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( return flask.render_template(
"accommodation.html", "accommodation.html",
items=items, items=items,