BUILD129 — три настраиваемых цвета команд

This commit is contained in:
2026-09-10 11:05:16 +03:00
parent f4f80d7837
commit a9278b5251
8 changed files with 243 additions and 62 deletions

View File

@@ -16,6 +16,7 @@ from .service import HockeyDataService
from .models import (
Game,
GameControlState,
Team,
Tournament,
MappingContextValue,
MappingContextVariable,
@@ -855,6 +856,12 @@ class MappingDataService:
control = session.scalar(
select(GameControlState).where(GameControlState.game_external_id == game_id)
)
home_team = session.scalar(
select(Team).where(Team.external_id == str(game.home_team_external_id or ""))
) if game.home_team_external_id else None
away_team = session.scalar(
select(Team).where(Team.external_id == str(game.away_team_external_id or ""))
) if game.away_team_external_id else None
current_period = str(getattr(control, "current_period", "1") or "1")
stage = stage_key(
str(getattr(tournament, "season_part", "") or ""),
@@ -878,6 +885,47 @@ class MappingDataService:
language=language,
)
result: list[dict[str, Any]] = []
# BUILD129: operator-managed team colours. Enabled is deliberately a
# separate value from the HEX string so a colour may remain configured
# while being disabled for the current graphics logic.
for side, team, side_label in (("home", home_team, "Хозяева"), ("away", away_team, "Гости")):
color_specs = (
(1, "color_hex", "color_enabled"),
(2, "color_2_hex", "color_2_enabled"),
(3, "color_3_hex", "color_3_enabled"),
)
for index, color_field, enabled_field in color_specs:
raw_color = str(getattr(team, color_field, "") or "") if team is not None else ""
enabled = bool(getattr(team, enabled_field, False)) if team is not None else False
result.append({
"key": f"team.{side}.color{index}",
"label": f"Цвет {index}",
"category": f"Команды · Цвета · {side_label}",
"value": raw_color if enabled else "",
"kind": "color",
"source_code": "live_control",
"description": f"Цвет {index} команды. Пусто, если цвет выключен в справочнике команд.",
})
result.append({
"key": f"team.{side}.color{index}_enabled",
"label": f"Цвет {index} включён (1/0)",
"category": f"Команды · Цвета · {side_label}",
"value": "1" if enabled else "0",
"kind": "text",
"source_code": "live_control",
"description": f"1 — цвет {index} включён; 0 — отключён оператором.",
})
result.append({
"key": f"team.{side}.color{index}_raw",
"label": f"Цвет {index} · сохранённый HEX",
"category": f"Команды · Цвета · {side_label}",
"value": raw_color,
"kind": "color",
"source_code": "live_control",
"description": f"Сохранённый HEX цвета {index}, независимо от флага включения.",
})
score_control = HockeyDataService._score_control_payload(game, control)
score_fields = (
("home", "Счёт HOME · LIVE", score_control["home"], "Оперативный счёт HOME. После первого ручного +/- становится главным до синхронизации."),