маппинг
This commit is contained in:
@@ -88,6 +88,18 @@ from .tournament_statistics_parser import parse_tournament_statistics_xml
|
||||
from .navigation_labels import parse_navigation_labels_xml
|
||||
|
||||
|
||||
def normalise_team_color_hex(value: Any) -> str:
|
||||
"""Return an uppercase #RRGGBB value or an empty string for unset colours."""
|
||||
raw_color = str(value or "").strip().upper()
|
||||
if not raw_color:
|
||||
return ""
|
||||
if not raw_color.startswith("#"):
|
||||
raw_color = f"#{raw_color}"
|
||||
if not re.fullmatch(r"#[0-9A-F]{6}", raw_color):
|
||||
raise ValueError("Цвет команды должен быть в формате #RRGGBB")
|
||||
return raw_color
|
||||
|
||||
|
||||
DEFAULT_PENALTY_TYPES: tuple[tuple[str, str, str, str], ...] = (
|
||||
("TRIP", "Подножка", "Tripping", "2"),
|
||||
("HOOK", "Задержка клюшкой", "Hooking", "2"),
|
||||
@@ -596,6 +608,7 @@ class HockeyDataService:
|
||||
"short_name_en": team.short_name_en,
|
||||
"city_ru": team.city_ru,
|
||||
"city_en": team.city_en,
|
||||
"color_hex": team.color_hex,
|
||||
"logo_url": team.logo_url,
|
||||
"source": membership.source,
|
||||
"active": bool(membership.active),
|
||||
@@ -742,6 +755,10 @@ class HockeyDataService:
|
||||
):
|
||||
if field in payload and payload[field] is not None:
|
||||
setattr(team, field, str(payload[field]).strip())
|
||||
|
||||
if "color_hex" in payload and payload["color_hex"] is not None:
|
||||
team.color_hex = normalise_team_color_hex(payload["color_hex"])
|
||||
|
||||
if not (team.name_ru or team.name_en):
|
||||
raise ValueError("Укажите название команды на русском или английском")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user