- signage_schedules (Alembic 0030): entries {playlist, days, hours (may pass
midnight), dates, priority} and a fallback playlist. A screen's `schedule`
(ref) wins over its single playlist.
- services/signage_schedule.pick (pure): highest priority, then the most
specific (dates > days > hours), then the later entry; no match → fallback.
- GET /api/signage/screen with a schedule: the schedule (with the venue's time
zone) and every playlist in it, `playlist` = the one playing now, so the
player can switch while the server is down.
- schedule_worker (signage module, 30 s) tells a screen when its pick changes.
- /api/signage/schedules CRUD (playing now, the screens on it); deleting a
playlist takes it out of schedules; changes reach screens through schedules.
- Devices page: a signage screen's Schedule.
- tests: test_signage_schedule.py (6); 526 passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
3.5 KiB
Python
68 lines
3.5 KiB
Python
"""Digital signage (plan steps 5.4a-5.4d): playlists of slides for TVs.
|
|
|
|
A playlist is made for one orientation (the people who build it see the screen's shape) and
|
|
holds slides in order. A slide is a menu board, a full-screen picture, a full-screen video or
|
|
a text, with its time on screen, its transition and when it may show (days, hours, dates).
|
|
What the slide shows is `content`, typed per kind in routers/signage.py (pictures and videos
|
|
as media library ids, which the library protects while used).
|
|
|
|
A paired signage screen plays the playlist in its device config (`playlist`), in its own
|
|
orientation and rotation (modules/signage/manifest.py).
|
|
"""
|
|
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from core.timeutil import UTCDateTime, utcnow
|
|
from database import Base
|
|
|
|
|
|
class SignagePlaylist(Base):
|
|
__tablename__ = "signage_playlists"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False)
|
|
orientation = Column(String, nullable=False, default="landscape") # landscape | portrait
|
|
transition = Column(String, nullable=False, default="fade") # the slides' default
|
|
created_at = Column(UTCDateTime, default=utcnow, nullable=False)
|
|
updated_at = Column(UTCDateTime, default=utcnow, onupdate=utcnow, nullable=False)
|
|
|
|
slides = relationship("SignageSlide", back_populates="playlist", cascade="all, delete-orphan",
|
|
order_by="SignageSlide.position")
|
|
|
|
|
|
class SignageSlide(Base):
|
|
__tablename__ = "signage_slides"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
playlist_id = Column(Integer, ForeignKey("signage_playlists.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
position = Column(Integer, nullable=False, default=0)
|
|
kind = Column(String, nullable=False) # menu | image | video | text
|
|
name = Column(String, nullable=True) # the timeline's label (optional)
|
|
duration_s = Column(Integer, nullable=False, default=10)
|
|
transition = Column(String, nullable=True) # None: the playlist's
|
|
video_to_end = Column(Boolean, nullable=False, default=False)
|
|
enabled = Column(Boolean, nullable=False, default=True)
|
|
# When it may show (venue time); empty = always
|
|
days = Column(JSON, nullable=True) # [0..6], Monday = 0
|
|
time_from = Column(String, nullable=True) # "HH:MM"
|
|
time_to = Column(String, nullable=True) # "HH:MM" (may pass midnight)
|
|
date_from = Column(String, nullable=True) # "YYYY-MM-DD"
|
|
date_to = Column(String, nullable=True)
|
|
content = Column(JSON, nullable=False, default=dict)
|
|
|
|
playlist = relationship("SignagePlaylist", back_populates="slides")
|
|
|
|
|
|
class SignageSchedule(Base):
|
|
"""Which playlist plays when (5.4d): entries matched in venue time (services/signage_schedule.py),
|
|
the fallback when none matches. A screen with a schedule plays it instead of a single playlist."""
|
|
__tablename__ = "signage_schedules"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False)
|
|
fallback_playlist_id = Column(Integer, ForeignKey("signage_playlists.id", ondelete="SET NULL"), nullable=True)
|
|
# [{playlist_id, days, time_from, time_to, date_from, date_to, priority}]
|
|
entries = Column(JSON, nullable=False, default=list)
|
|
created_at = Column(UTCDateTime, default=utcnow, nullable=False)
|
|
updated_at = Column(UTCDateTime, default=utcnow, onupdate=utcnow, nullable=False)
|