From e1540d9bfe36e7c5ce555401cc7ad2fe42317813 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 4 Dec 2023 23:01:14 +0000 Subject: [PATCH] Split conference list current, future, past --- templates/conference_list.html | 42 +++++++++++++++++++--------------- web_view.py | 17 ++++++++++---- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/templates/conference_list.html b/templates/conference_list.html index a0e891b..1c44e02 100644 --- a/templates/conference_list.html +++ b/templates/conference_list.html @@ -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 */ +} {% endblock %} +{% macro row(item) %} +
{{ item.start.strftime("%a, %d %b %Y") }}
+
{{ item.end.strftime("%a, %d %b") }}
+
{{ item.name }}
+
{{ item.topic }}
+
{{ item.location }}
+
{{ item.url }}
+{% endmacro %} + +{% macro section(heading, item_list) %} +{% if item_list %} +

{{heading}}

+{% for item in item_list %}{{ row(item) }}{% endfor %} +{% endif %} +{% endmacro %} + {% block content %}
@@ -30,26 +50,10 @@

- {% for item in item_list %} - {% if item == "today" %} - {% set bg="bg-warning-subtle" %} -
{{ today.strftime("%a, %d %b %Y") }}
-
-
today
-
-
-
- {% else %} -
{{ item.start.strftime("%a, %d %b %Y") }}
-
{{ item.end.strftime("%a, %d %b") }}
-
{{ item.name }}
-
{{ item.topic }}
-
{{ item.location }}
- - {% endif %} - {% endfor %} + {{ section("Current", current) }} + {{ section("Future", future) }} + {{ section("Past", past|reverse) }}
-
{% endblock %} diff --git a/web_view.py b/web_view.py index 1b5e826..0bcfe69 100755 --- a/web_view.py +++ b/web_view.py @@ -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 )