feat(signage): gallery widget (pictures and videos one after another, from a list or a media folder); media folders on the Media page

Folders are only a grouping in the database (media_folders, media.folder_id, Alembic
0046): made, renamed, deleted (files stay) on the Media page, a file filed from its
details, uploads go into the folder shown, the picker filters by folder. The gallery
widget: its own pictures/videos in order or a folder as it is now, seconds each,
fade / slide / zoom, cover / contain. Plan 6R.16, F-114.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 14:41:17 +02:00
co-authored by Claude Opus 5.5
parent 189bd2777b
commit 1eb7e5e3a9
24 changed files with 549 additions and 51 deletions
+20 -1
View File
@@ -86,7 +86,7 @@ class Background(_Strict):
WidgetKind = Literal["logo", "name", "date", "clock", "message", "qr", "weather", "text", "menu", "stack",
"shape", "ticker", "countdown", "hours", "wifi", "contact", # 6R.15
"reviews"] # 6R.19
"reviews", "gallery"] # 6R.19, 6R.16
WHEN = r"^(\d{4}-\d{2}-\d{2}T)?([01]\d|2[0-3]):[0-5]\d$" # a countdown's moment: "HH:MM" (every day) or "YYYY-MM-DDTHH:MM"
ContactKey = Literal["phone", "phone2", "email", "address", "website", "google", "facebook", "instagram", "tiktok", "tripadvisor", "whatsapp", "viber"]
Position = Literal["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right", "top-bar", "bottom-bar", "custom"]
@@ -316,6 +316,13 @@ class Widget(_Strict):
reviews_min: int = Field(default=4, ge=1, le=5) # only reviews with at least these stars
reviews_stars: bool = True
reviews_name: bool = True
# a gallery (6R.16): pictures and videos one after another, from its own list or a media folder
gallery_source: Literal["pictures", "folder"] = "pictures"
media_ids: List[int] = Field(default_factory=list, max_length=100)
gallery_folder: Optional[int] = None
gallery_seconds: int = Field(default=5, ge=3, le=120)
gallery_transition: Literal["fade", "slide", "zoom", "none"] = "fade"
gallery_fit: Literal["cover", "contain"] = "cover"
@model_validator(mode="after")
def _place(self):
@@ -661,6 +668,10 @@ def extras(db, content: dict, keep_hidden: bool = False, depth: int = 0):
out[path] = {"link": _qr_link(w)}
elif w.get("kind") == "menu":
out[path] = {"menu": resolve(db, w.get("board") or {}, keep_hidden=keep_hidden)}
elif w.get("kind") == "gallery" and w.get("gallery_source") == "folder":
ids = gallery_folder_ids(db, w.get("gallery_folder")) # 6R.16: the folder as it is now
out[path] = {"gallery": ids}
mids += ids
elif depth == 0:
s = db.get(SignageSavedSlide, sid)
if s is None:
@@ -675,6 +686,14 @@ def extras(db, content: dict, keep_hidden: bool = False, depth: int = 0):
return out, mids
def gallery_folder_ids(db, folder_id) -> list[int]:
"""A media folder's files for a gallery (6R.16), newest last as uploaded; none for a folder that's gone."""
from models.media import Media
if not folder_id:
return []
return [m.id for m in db.query(Media).filter(Media.folder_id == folder_id).order_by(Media.created_at, Media.id).limit(200)]
def _content(db, kind: str, raw: dict | None) -> dict:
"""The content as stored: typed for its kind, every media id an existing file of the right kind."""
from pydantic import ValidationError