Tidy code for conference list

This commit is contained in:
Edward Betts 2024-04-08 09:11:22 +02:00
parent 291b545915
commit b1507702cf

View file

@ -139,7 +139,7 @@ def conference_list() -> str:
"""Page showing a list of conferences.""" """Page showing a list of conferences."""
data_dir = app.config["PERSONAL_DATA"] data_dir = app.config["PERSONAL_DATA"]
filepath = os.path.join(data_dir, "conferences.yaml") filepath = os.path.join(data_dir, "conferences.yaml")
item_list = yaml.safe_load(open(filepath)) items = yaml.safe_load(open(filepath))
today = date.today() today = date.today()
conference_trip_lookup = {} conference_trip_lookup = {}
@ -148,7 +148,7 @@ def conference_list() -> str:
key = (trip_conf["start"], trip_conf["name"]) key = (trip_conf["start"], trip_conf["name"])
conference_trip_lookup[key] = trip conference_trip_lookup[key] = trip
for conf in item_list: for conf in items:
conf["start_date"] = as_date(conf["start"]) conf["start_date"] = as_date(conf["start"])
conf["end_date"] = as_date(conf["end"]) conf["end_date"] = as_date(conf["end"])
@ -156,16 +156,15 @@ def conference_list() -> str:
if this_trip := conference_trip_lookup.get(key): if this_trip := conference_trip_lookup.get(key):
conf["linked_trip"] = this_trip 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 = [ current = [
conf conf
for conf in item_list for conf in items
if conf["start_date"] <= today and conf["end_date"] >= today if conf["start_date"] <= today and conf["end_date"] >= today
] ]
future = [conf for conf in items if conf["start_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( return flask.render_template(
"conference_list.html", "conference_list.html",