feat(signage): new widgets (shape, scrolling text, countdown, opening hours, Wi-Fi, contact details); the venue's opening hours on the server, edited on the Schedule page
Shapes: rectangle, circle, triangle, polygon, star or own corners, fill or gradient, border. Countdown: to a time every day or a date, from now / a span before / a set time, in venue time (the slide shows what is left right now). Opening hours, Wi-Fi (with a join-the-network code) and contact details read the venue's identity and opening hours (GET/PUT /api/identity/hours; Schedule -> Opening hours, shaded on its timeline); the editor warns with a link when they're missing. Plan 6R.15, F-112. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
"""The venue's identity (6R.14, owner 2026-11-22): set once, used by every app that shows the venue.
|
||||
|
||||
GET /api/identity its name, slogan, colours, logos, Wi-Fi and contact details (anyone who opens the manager)
|
||||
PUT /api/identity all of it at once (core.settings.manage)
|
||||
GET /api/identity its name, slogan, colours, logos, Wi-Fi and contact details (anyone who opens the manager)
|
||||
PUT /api/identity all of it at once (core.settings.manage)
|
||||
GET /api/identity/hours the opening hours, Monday first (6R.15)
|
||||
PUT /api/identity/hours {days: [[{from, to}], … 7], note} (core.settings.manage or core.staff.manage: the Schedule page)
|
||||
|
||||
Stored as the settings `venue.name` (the name everything already shows) and `venue.identity` (JSON,
|
||||
the rest). Logos are media library pictures, protected while used. Signage screens get it with
|
||||
@@ -17,12 +19,14 @@ from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from core.access.deps import require
|
||||
from core.access.deps import require, require_any
|
||||
from core.errors import XeniaError
|
||||
from database import get_db
|
||||
|
||||
router = APIRouter()
|
||||
KEY = "venue.identity"
|
||||
HOURS = "venue.opening_hours"
|
||||
TIME = r"^([01]\d|2[0-3]):[0-5]\d$"
|
||||
HEX = r"^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$"
|
||||
LOGOS = ("main", "light", "dark", "icon")
|
||||
|
||||
@@ -191,3 +195,57 @@ def put_identity(body: IdentityBody, db: Session = Depends(get_db), user=Depends
|
||||
except Exception:
|
||||
pass # signage not installed / off: nothing to tell
|
||||
return identity_out(db)
|
||||
|
||||
|
||||
# ── opening hours (6R.15): edited on the Schedule page, shown by signage's opening hours widget ──
|
||||
|
||||
class Span(_Strict):
|
||||
"""Open from … to … (venue time; `to` before `from` passes midnight)."""
|
||||
from_: str = Field(alias="from", pattern=TIME)
|
||||
to: str = Field(pattern=TIME)
|
||||
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
||||
|
||||
|
||||
class Hours(_Strict):
|
||||
days: List[List[Span]] = Field(default_factory=lambda: [[] for _ in range(7)]) # Monday first; [] = closed
|
||||
note: Optional[str] = Field(default=None, max_length=120) # "Closed on holidays"
|
||||
|
||||
@field_validator("days")
|
||||
@classmethod
|
||||
def _seven(cls, v):
|
||||
if len(v) != 7 or any(len(d) > 3 for d in v):
|
||||
raise ValueError("seven days, up to three spans a day")
|
||||
return v
|
||||
|
||||
@field_validator("note")
|
||||
@classmethod
|
||||
def _note(cls, v):
|
||||
return _text(v, 120)
|
||||
|
||||
|
||||
def hours_out(db) -> dict:
|
||||
"""{days: [[{from, to}]…7], note, set}: `set` false while no day has hours."""
|
||||
try:
|
||||
h = Hours(**json.loads(_setting(db, HOURS) or "{}"))
|
||||
except Exception:
|
||||
h = Hours()
|
||||
days = [[{"from": x.from_, "to": x.to} for x in d] for d in h.days]
|
||||
return {"days": days, "note": h.note, "set": any(days)}
|
||||
|
||||
|
||||
@router.get("/hours")
|
||||
def get_hours(db: Session = Depends(get_db), user=Depends(require("core.dashboard.access"))):
|
||||
return hours_out(db)
|
||||
|
||||
|
||||
@router.put("/hours")
|
||||
def put_hours(body: Hours, db: Session = Depends(get_db), user=Depends(require_any("core.settings.manage", "core.staff.manage"))):
|
||||
days = [[{"from": x.from_, "to": x.to} for x in sorted(d, key=lambda x: x.from_)] for d in body.days]
|
||||
_save(db, HOURS, json.dumps({"days": days, "note": body.note}, ensure_ascii=False))
|
||||
db.commit()
|
||||
try:
|
||||
from routers.signage import tell_all_screens
|
||||
tell_all_screens(db)
|
||||
except Exception:
|
||||
pass
|
||||
return hours_out(db)
|
||||
|
||||
Reference in New Issue
Block a user