feat(backend): signage previews for the editor: menu boards resolved, a draft menu, the widgets' venue (platform-v2 step 5.6a)

GET /api/signage/playlists/{id} gives each menu slide its resolved `menu`;
POST /api/signage/preview/menu resolves a menu board not saved yet; GET
/api/signage/venue gives what the widgets show. 527 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 20:59:33 +02:00
co-authored by Claude Opus 5.5
parent 314e9c2457
commit 4d63216167
2 changed files with 36 additions and 0 deletions
+25
View File
@@ -390,7 +390,11 @@ def _playlist_out(db, p: SignagePlaylist, slides: bool = False) -> dict:
out = {"id": p.id, "name": p.name, "orientation": p.orientation, "transition": p.transition,
"slide_count": len(p.slides), "screens": [{"id": d.id, "name": d.name} for d in _screens(db) if d.id in playing]}
if slides:
from services.signage_menu import resolve
out["slides"] = [_slide_out(s) for s in p.slides]
for s in out["slides"]:
if s["kind"] == "menu":
s["menu"] = resolve(db, s["content"]) # the editor's preview (5.6a)
out["media"] = _media_map(db, [i for s in p.slides for i in media_ids(s.content or {})])
return out
@@ -811,3 +815,24 @@ async def weather_places(q: str, language: str = "en", user=Depends(require(KEY)
return await weather.search(q.strip(), language if language in ("en", "el") else "en")
except Exception:
raise XeniaError("signage.weather_offline")
# ── for the editor's previews (5.6a) ───────────────────────────────────────────
class MenuPreviewBody(BaseModel):
content: dict = Field(default_factory=dict)
@router.get("/venue")
def preview_venue(db: Session = Depends(get_db), user=Depends(require(KEY))):
"""What the widgets show (the same as a screen gets), for the editor's previews."""
from services import weather
return {"name": _setting(db, "venue.name") or None, "message": _setting(db, MESSAGE) or None, "weather": weather.current(db)}
@router.post("/preview/menu")
def preview_menu(body: MenuPreviewBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
"""A menu board not saved yet, resolved like a screen gets it (the editor's live preview)."""
from services.signage_menu import resolve
content = _content(db, "menu", body.content)
return {"content": content, "menu": resolve(db, content)}
+11
View File
@@ -138,3 +138,14 @@ def test_menu_settings_are_checked(client, owner_h, tv):
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": {"badges": {"x": "new"}}})) == "signage.content_invalid"
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": {"badges": {"3": "shiny"}}})) == "signage.content_invalid"
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": {"columns": 4}})) == "signage.content_invalid"
def test_the_editor_previews(client, owner_h, tv, menu):
s, _ = board(client, owner_h, tv, category_ids=[menu["cats"]["drinks"]])
got = client.get(f"/api/signage/playlists/{tv['playlist']}", headers=owner_h).json()
assert names(next(x for x in got["slides"] if x["id"] == s["id"])["menu"]) == [["Drinks", ["Beer"]]] # Wine: delivery only
draft = client.post("/api/signage/preview/menu", headers=owner_h, json={"content": {"product_ids": [menu["steak"].id], "sales_point": None}}).json()
assert names(draft["menu"]) == [["Grill", ["Steak"]]] and draft["content"]["columns"] == 2
assert err(client.post("/api/signage/preview/menu", headers=owner_h, json={"content": {"columns": 9}})) == "signage.content_invalid"
client.put("/api/signage/message", headers=owner_h, json={"text": "Hello"})
assert client.get("/api/signage/venue", headers=owner_h).json() == {"name": None, "message": "Hello", "weather": None}