# -*- coding: utf-8 -*- """Étape 6 — ordre d'affichage des sections. La création réinsère chaque nouvelle section en tête ; l'ordre final est donc l'inverse de l'ordre de saisie. On le remet dans l'ordre de lecture voulu. """ import json from pathlib import Path from api import Api STATE = Path(__file__).resolve().parent / "state.json" ORDER = { "feschmaart": [ "Collections", "Mosaïque de Vichten", "Goeblange-Nospelt", "Villeroy & Boch Art déco", "Cabinet des médailles", "Le secret de la villa", "Quiz archéologie", "Expositions et rendez-vous", ], "draieechelen": [ "Fort Thüngen", "Démantèlement 1867", "Maquettes et plans-reliefs", ], "echternach": [ "Parcours extérieur", "Sur les pas du maître", "La villa romaine", "Thermes et hypocauste", ], } def main(): api = Api() state = json.loads(STATE.read_text(encoding="utf-8")) for key, labels in ORDER.items(): config_id = state["configs"][key] sections = api.get(f"/api/Section/configuration/{config_id}") or [] by_label = {s["label"]: s for s in sections} for order, label in enumerate(labels): section = by_label.get(label) if not section: print(f" ! introuvable : {key} / {label}") continue detail = api.get(f"/api/Section/{section['id']}") api.put("/api/Section", {**detail, "order": order}) final = api.get(f"/api/Section/configuration/{config_id}") or [] ordered = sorted(final, key=lambda s: s["order"]) print(f" {key}: " + " | ".join(s["label"] for s in ordered)) if __name__ == "__main__": main()