diff --git a/plugins/talks/talks.py b/plugins/talks/talks.py index 7bcb85d..d7be198 100644 --- a/plugins/talks/talks.py +++ b/plugins/talks/talks.py @@ -100,6 +100,10 @@ def get_global_data(): data["startdate"] = datetime.datetime.now() if "rooms" not in data: data["rooms"] = {} + if "names" not in data["rooms"]: + data["rooms"]["names"] = {} + if "order" not in data["rooms"]: + data["rooms"]["order"] = [] return data @@ -169,8 +173,8 @@ def get_talk_data(talkname): if "room" not in data: logging.warn("Talk <{}> has no `room` field".format(talkname)) else: - if data["room"] in get_global_data()["rooms"]: - data["room"] = get_global_data()["rooms"][data["room"]] + if data["room"] in get_global_data()["rooms"]["names"]: + data["room"] = get_global_data()["rooms"]["names"][data["room"]] if "time" not in data or "day" not in data: logging.warn("Talk <{}> has no `time` or `day`".format(talkname)) if "time" in data: @@ -371,8 +375,22 @@ class TalkGridDirective(Directive): rooms.add(r) else: rooms.add(t["room"]) - # TODO: ordina in base a qualcosa nel meta.yaml globale - rooms = list(sorted(rooms)) + + def _room_sort_key(r): + order = get_global_data()["rooms"]["order"] + base = None + for k, v in get_global_data()["rooms"]["names"].items(): + if v == r: + base = k + break + else: + if type(r) is str: + return ord(r[0]) + # int? + return r + return order.index(base) + + rooms = list(sorted(rooms, key=_room_sort_key)) # room=* is not a real room. # Remove it unless that day only has special rooms diff --git a/talks/meta.yaml b/talks/meta.yaml index 5ca8453..ab75d08 100644 --- a/talks/meta.yaml +++ b/talks/meta.yaml @@ -1,6 +1,8 @@ startdate: 2019-05-30 rooms: - A: Bistrot - B: Sala Biliardo (grande) - C: Hangar - D: Sala concerti + names: + A: Bistrot + B: Sala Biliardo (grande) + C: Hangar + D: Sala concerti + order: [A,B,C,D]