Files
shopdb-flask/shopdb/core/models/dashboarddefault.py
cproudlock 60e2947fc7 displays: single display type with IP-driven role (dashboard/lobby/kiosk)
One 'display' image resolves what it shows from its own IP, like the existing
visitor-location BU mapping. Extend DashboardDefault with displayrole
(dashboard|lobby|partskiosk; migration 7d28, businessunitid now nullable since
only the dashboard role needs one) + a role->path map. New unauthenticated
GET /api/dashboarddefaults/display-role returns {role, path, businessunitid}
for the caller IP. Settings UI gains a Display selector, showing the business
unit only for the dashboard role.
2026-07-21 09:49:14 -04:00

45 lines
1.5 KiB
Python

"""Dashboard default model: display-PC-IP -> display role (+ business unit).
A single "display" PC image resolves what it should show from its own IP: the
role (shopfloor dashboard, lobby slideshow, or 3D-parts kiosk) and, for the
dashboard role, which business unit. Powers the visitor-location + display-role
lookups the kiosks call at launch.
"""
from shopdb.extensions import db
from .base import BaseModel
# Display role -> the frontend kiosk path it maps to. Kept here so the API and
# any consumer resolve a role to a URL the same way.
DISPLAY_ROLE_PATHS = {
'dashboard': '/shopfloor',
'lobby': '/tv',
'partskiosk': '/parts-kiosk',
}
DISPLAY_ROLES = tuple(DISPLAY_ROLE_PATHS.keys())
class DashboardDefault(BaseModel):
"""Maps a display PC IP address to its display role (+ business unit)."""
__tablename__ = 'dashboarddefaults'
dashboarddefaultid = db.Column(db.Integer, primary_key=True)
ipaddress = db.Column(db.String(50), unique=True, nullable=False)
# Which display the IP drives. Only the dashboard role uses businessunitid.
displayrole = db.Column(db.String(20), nullable=False, default='dashboard')
businessunitid = db.Column(
db.Integer,
db.ForeignKey('businessunits.businessunitid'),
nullable=True
)
description = db.Column(db.String(255))
businessunit = db.relationship('BusinessUnit')
@property
def displaypath(self):
return DISPLAY_ROLE_PATHS.get(self.displayrole)
def __repr__(self):
return f"<DashboardDefault {self.ipaddress} -> {self.displayrole}>"