From b1507702cf3df3d23b70146f38db4209e70d8bf0 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 8 Apr 2024 09:11:22 +0200 Subject: [PATCH] Tidy code for conference list --- web_view.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/web_view.py b/web_view.py index d34be5d..09f53ce 100755 --- a/web_view.py +++ b/web_view.py @@ -139,7 +139,7 @@ def conference_list() -> str: """Page showing a list of conferences.""" data_dir = app.config["PERSONAL_DATA"] filepath = os.path.join(data_dir, "conferences.yaml") - item_list = yaml.safe_load(open(filepath)) + items = yaml.safe_load(open(filepath)) today = date.today() conference_trip_lookup = {} @@ -148,7 +148,7 @@ def conference_list() -> str: key = (trip_conf["start"], trip_conf["name"]) conference_trip_lookup[key] = trip - for conf in item_list: + for conf in items: conf["start_date"] = as_date(conf["start"]) conf["end_date"] = as_date(conf["end"]) @@ -156,16 +156,15 @@ def conference_list() -> str: if this_trip := conference_trip_lookup.get(key): conf["linked_trip"] = this_trip - item_list.sort(key=operator.itemgetter("start_date")) + items.sort(key=operator.itemgetter("start_date")) + past = [conf for conf in items if conf["end_date"] < today] current = [ conf - for conf in item_list + for conf in items 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] + future = [conf for conf in items if conf["start_date"] > today] return flask.render_template( "conference_list.html",