добавил возможность администраторам создавать игроков, тренеров и судей вручную

This commit is contained in:
2026-08-04 10:49:03 +03:00
parent 2c2d9b9a7c
commit adea3a8bd6
10 changed files with 891 additions and 3 deletions

View File

@@ -544,3 +544,101 @@ def update_player_photo_enabled(player_id: int, photo_enabled: bool = False) ->
raise
finally:
conn.close()
def create_player_admin(
team_id: int,
full_name: str,
first_name: str = "",
last_name: str = "",
external_id: str = "",
number: str = "",
position: str = "",
birth_date: str = "",
photo: str = "",
video: str = "",
height_cm: int | None = None,
weight_kg: int | None = None,
games: int = 0,
goals: int = 0,
penaltys: int = 0,
assists: int = 0,
yellows: int = 0,
reds: int = 0,
is_active: bool = True,
photo_enabled: bool = False,
) -> int:
"""Создаёт игрока вручную из административного раздела."""
query = """
INSERT INTO players (
external_id,
team_id,
full_name,
first_name,
last_name,
number,
position,
pos,
amplua,
born,
photo,
video,
height_cm,
weight_kg,
games,
goals,
penaltys,
assists,
yellows,
reds,
is_active,
photo_enabled,
created_at,
updated_at
)
VALUES (
NULLIF(%s, ''), %s, %s, %s, %s, NULLIF(%s, ''), %s, %s, %s,
NULLIF(%s, '')::date, NULLIF(%s, ''), NULLIF(%s, ''), %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW()
)
RETURNING id;
"""
conn = get_connection()
try:
with conn.cursor() as cur:
cur.execute(
query,
(
external_id.strip(),
int(team_id),
full_name.strip(),
first_name.strip(),
last_name.strip(),
number.strip(),
position.strip(),
position.strip(),
position.strip(),
birth_date.strip(),
photo.strip(),
video.strip(),
height_cm,
weight_kg,
int(games),
int(goals),
int(penaltys),
int(assists),
int(yellows),
int(reds),
bool(is_active),
bool(photo_enabled),
),
)
row = cur.fetchone()
conn.commit()
return int(row[0])
except Exception:
conn.rollback()
raise
finally:
conn.close()