Split conference list current, future, past

This commit is contained in:
Edward Betts 2023-12-04 23:01:14 +00:00
parent 0fa6a2cdda
commit e1540d9bfe
2 changed files with 35 additions and 24 deletions

View file

@ -12,9 +12,29 @@
.grid-item {
/* Additional styling for grid items can go here */
}
.heading {
grid-column: 1 / 7; /* Spans from the 1st line to the 7th line */
}
</style>
{% endblock %}
{% macro row(item) %}
<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 }}</div>
<div class="grid-item">{{ item.topic }}</div>
<div class="grid-item">{{ item.location }}</div>
<div class="grid-item"><a href="{{ item.url }}">{{ item.url }}</a></div>
{% endmacro %}
{% macro section(heading, item_list) %}
{% if item_list %}
<div class="heading"><h2>{{heading}}</h2></div>
{% for item in item_list %}{{ row(item) }}{% endfor %}
{% endif %}
{% endmacro %}
{% block content %}
<div class="container-fluid mt-2">
@ -30,26 +50,10 @@
</p>
<div class="grid-container">
{% for item in item_list %}
{% if item == "today" %}
{% set bg="bg-warning-subtle" %}
<div class="grid-item text-end {{ bg }}">{{ today.strftime("%a, %d %b %Y") }}</div>
<div class="{{ bg }}"></div>
<div class="{{ bg }}">today</div>
<div class="{{ bg }}"></div>
<div class="{{ bg }}"></div>
<div class="{{ bg }}"></div>
{% else %}
<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 }}</div>
<div class="grid-item">{{ item.topic }}</div>
<div class="grid-item">{{ item.location }}</div>
<div class="grid-item"><a href="{{ item.url }}">{{ item.url }}</a></div>
{% endif %}
{% endfor %}
{{ section("Current", current) }}
{{ section("Future", future) }}
{{ section("Past", past|reverse) }}
</div>
</div>
{% endblock %}

View file

@ -82,15 +82,22 @@ def conference_list() -> str:
item_list = yaml.safe_load(open(filepath))["conferences"]
today = date.today()
for conf in item_list:
conf["as_date"] = as_date(conf["start"])
conf["start_date"] = as_date(conf["start"])
conf["end_date"] = as_date(conf["end"])
item_list.sort(key=operator.itemgetter("as_date"))
item_list.sort(key=operator.itemgetter("start_date"))
past = [conf for conf in item_list if conf["as_date"] < today]
future = [conf for conf in item_list if conf["as_date"] >= today]
current = [
conf
for conf in item_list
if conf["start_date"] <= today and conf["end_date"] >= today
]
past = [conf for conf in item_list if conf["end_date"] < today]
future = [conf for conf in item_list if conf["start_date"] > today]
return flask.render_template(
"conference_list.html", item_list=past + ["today"] + future, today=today
"conference_list.html", current=current, past=past, future=future, today=today
)