feat(signage,scenes): schedule lines with screens and smart days, screens' defaults, horizontal timeline, scenes

- Scenes (Alembic 0043, models/scene.py, /api/scenes, core.scenes.manage): named
  modes on or off (optionally until a time); price rules / deals get the
  condition "a scene is on"; signage lines can play only during a scene;
  turning one on tells every screen and pushes the online menu.
- Signage schedules are lines (signage_schedule_items): playlist, screens
  ([] = every screen), priority, days, smart days (1st / last day, first / last
  week, Greek public holidays or not: core/calendar_days.py, mirrored in
  @xenia/signage), hours, dates, scene. No line → the screen's default
  playlist. 0043 turns the old named schedules into lines for their screens.
- Screens: default playlist, TV shape, turn; what plays now and why.
- Manager: tabs Screens · Playlists · Schedules · Slides (placeholder) ·
  Message and weather; schedule lines with playlist / screens / priority /
  delete on one line; the playlist editor's horizontal timeline of fixed
  cards, the slide's basics beside its preview (one height), then its content;
  Management → Scenes; the scene condition in pricing.
- Tests: backend (lines, smart days, scenes, prices), player logic, e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 19:22:47 +02:00
co-authored by Claude Opus 5.5
parent abab158b7c
commit 60e6a16217
44 changed files with 1429 additions and 533 deletions
+53
View File
@@ -0,0 +1,53 @@
"""Smart day filters (owner 2026-11-21): the 1st / last day of the month, its first / last week, and
Greek public holidays (fixed dates and those that follow the Orthodox Easter).
The same rules in JavaScript: packages/signage/src/logic.js (a screen applies its schedule while
the server is down); both sides are tested with the same dates.
"""
from __future__ import annotations
import calendar
from datetime import date, timedelta
# the filters a schedule line can have: any one that holds is enough, except "not_holiday",
# which keeps the line off on public holidays
MONTH_DAYS = ("first", "last", "first_week", "last_week", "holiday", "not_holiday")
_FIXED = ((1, 1), (1, 6), (3, 25), (5, 1), (8, 15), (10, 28), (12, 25), (12, 26))
# days from the Orthodox Easter Sunday: Clean Monday, Good Friday, Easter Sunday, Easter Monday, Whit Monday
_FROM_EASTER = (-48, -2, 0, 1, 50)
def orthodox_easter(year: int) -> date:
"""The Orthodox Easter Sunday (Meeus' Julian algorithm, + 13 days to the Gregorian calendar, 1900-2099)."""
a, b, c = year % 4, year % 7, year % 19
d = (19 * c + 15) % 30
e = (2 * a + 4 * b - d + 34) % 7
month = (d + e + 114) // 31
day = (d + e + 114) % 31 + 1
return date(year, month, day) + timedelta(days=13)
def is_holiday(day: date) -> bool:
"""A Greek public holiday (nationwide)."""
if (day.month, day.day) in _FIXED:
return True
easter = orthodox_easter(day.year)
return any(day == easter + timedelta(days=n) for n in _FROM_EASTER)
def month_days_ok(tokens, day: date) -> bool:
"""Does a day pass a line's smart filters (empty = every day)?"""
tokens = [t for t in (tokens or []) if t in MONTH_DAYS]
if not tokens:
return True
hol = is_holiday(day)
if "not_holiday" in tokens and hol:
return False
wanted = [t for t in tokens if t != "not_holiday"]
if not wanted:
return True
last = calendar.monthrange(day.year, day.month)[1]
return any((t == "first" and day.day == 1) or (t == "last" and day.day == last)
or (t == "first_week" and day.day <= 7) or (t == "last_week" and day.day > last - 7)
or (t == "holiday" and hol) for t in wanted)
+4
View File
@@ -201,6 +201,10 @@ CODES: dict[str, tuple[int, str]] = {
"expense.document_not_found": (404, "Document not found."),
"channel_price.not_found": (404, "Channel price not found."),
"channel_price.set_one_product": (400, "A set price is for one product: pick one product (and no categories), or change the price by an amount or a percentage."),
"scene.not_found": (404, "Scene {scene_id} not found."),
"scene.until_past": (400, "That time has already passed: pick a later one."),
"signage.scene_unknown": (404, "Scene {scene_id} not found."),
"signage.screen_unknown": (404, "Screen {device_id} not found."),
"expense.document_type": (422, "Upload a PDF or a photo (JPG, PNG, WebP or HEIC)."),
"expense.document_too_big": (413, "The file is too big (at most {max_mb} MB)."),
"flag.not_found": (404, "Mark not found."),
@@ -59,9 +59,6 @@ def _ref_exists(source: str, value: int, db) -> bool:
from models.table import Table
t = db.get(Table, value)
return t is not None and bool(t.is_active)
if source == "signage_schedules":
from models.signage import SignageSchedule
return db.get(SignageSchedule, value) is not None
if source == "display_looks":
from models.display_look import DisplayLook
return db.get(DisplayLook, value) is not None