Show country names and flags on conference page
This commit is contained in:
parent
fd46f0a405
commit
17036d849f
|
@ -18,6 +18,7 @@ class Conference:
|
|||
location: str
|
||||
start: date | datetime
|
||||
end: date | datetime
|
||||
country: str | None = None
|
||||
venue: str | None = None
|
||||
address: str | None = None
|
||||
url: str | None = None
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block style %}
|
||||
{% set column_count = 7 %}
|
||||
<style>
|
||||
.grid-container {
|
||||
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;
|
||||
justify-content: start;
|
||||
}
|
||||
|
@ -14,12 +15,13 @@
|
|||
}
|
||||
|
||||
.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) 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.end.strftime("%a, %d %b") }}</div>
|
||||
<div class="grid-item">{{ item.name }}
|
||||
|
@ -37,6 +39,17 @@
|
|||
</div>
|
||||
<div class="grid-item">{{ item.topic }}</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>
|
||||
{% endmacro %}
|
||||
|
||||
|
|
17
web_view.py
17
web_view.py
|
@ -98,6 +98,13 @@ def as_date(d: date | datetime) -> date:
|
|||
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")
|
||||
def conference_list() -> str:
|
||||
"""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]
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue