feat: update application version to 0.8.37 and enhance training planning features
Deploy Development / deploy (push) Failing after 14s
Test Suite / pytest-backend (push) Successful in 5s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Failing after 2s
Test Suite / playwright-tests (push) Successful in 23s
Deploy Development / deploy (push) Failing after 14s
Test Suite / pytest-backend (push) Successful in 5s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Failing after 2s
Test Suite / playwright-tests (push) Successful in 23s
- Bumped application version to 0.8.37 in both backend and frontend files. - Updated training planning API to include new session assignment features, allowing for lead trainer and assistant trainer assignments. - Enhanced the TrainingPlanningPage to support dynamic loading of club member directories based on selected groups. - Improved validation for trainer assignments, ensuring only active club members can be assigned as trainers. - Updated changelog to reflect the new version and changes made in this release.
This commit is contained in:
1 parent
14745b347d
commit
c778d21b26
10 files changed
+597
-91
No files matched your search
@@ -12,6 +12,7 @@ from db import get_db, get_cursor, r2d
|
||||
from tenant_context import TenantContext, get_tenant_context, library_content_visibility_sql
|
||||
from club_tenancy import (
|
||||
assert_valid_governance_visibility,
|
||||
can_manage_club_org,
|
||||
is_platform_admin,
|
||||
library_content_visible_to_profile,
|
||||
)
|
||||
@@ -53,7 +54,7 @@ def _validate_variant_for_exercise(cur, exercise_id: Optional[int], variant_id:
|
||||
|
||||
def _can_access_group_for_create(cur, group_id: int, profile_id: int, role: str) -> None:
|
||||
cur.execute(
|
||||
"SELECT trainer_id, co_trainer_ids FROM training_groups WHERE id = %s",
|
||||
"SELECT trainer_id, co_trainer_ids, club_id FROM training_groups WHERE id = %s",
|
||||
(group_id,),
|
||||
)
|
||||
group = cur.fetchone()
|
||||
@@ -64,9 +65,83 @@ def _can_access_group_for_create(cur, group_id: int, profile_id: int, role: str)
|
||||
raise HTTPException(status_code=403, detail="Nur Trainer dürfen Trainingseinheiten erstellen")
|
||||
if role not in ["admin", "superadmin"]:
|
||||
if group["trainer_id"] != profile_id and profile_id not in co_trainers:
|
||||
raise HTTPException(
|
||||
status_code=403, detail="Nur der zuständige Trainer darf für diese Gruppe planen"
|
||||
)
|
||||
if not can_manage_club_org(cur, profile_id, int(group["club_id"]), role):
|
||||
raise HTTPException(
|
||||
status_code=403, detail="Nur der zuständige Trainer darf für diese Gruppe planen"
|
||||
)
|
||||
|
||||
|
||||
def _profile_active_in_club(cur, club_id: int, profile_id: int) -> bool:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT 1 FROM club_members
|
||||
WHERE club_id = %s AND profile_id = %s AND status = 'active'
|
||||
LIMIT 1
|
||||
""",
|
||||
(club_id, profile_id),
|
||||
)
|
||||
return cur.fetchone() is not None
|
||||
|
||||
|
||||
def _caller_may_assign_session_trainers(
|
||||
cur,
|
||||
group_row: Dict[str, Any],
|
||||
profile_id: int,
|
||||
role: str,
|
||||
unit_created_by: Optional[int],
|
||||
) -> bool:
|
||||
if is_platform_admin(role):
|
||||
return True
|
||||
cid = group_row.get("club_id")
|
||||
if cid is not None and can_manage_club_org(cur, profile_id, int(cid), role):
|
||||
return True
|
||||
if unit_created_by is not None and unit_created_by == profile_id:
|
||||
return True
|
||||
if group_row.get("trainer_id") == profile_id:
|
||||
return True
|
||||
co = group_row.get("co_trainer_ids") or []
|
||||
return profile_id in co
|
||||
|
||||
|
||||
def _effective_co_trainer_ids_for_row(unit_row: Dict[str, Any]) -> List[int]:
|
||||
"""Leseregel: Session-Co-Trainer überschreiben die Gruppe; NULL auf der Einheit = Gruppen-Standard."""
|
||||
unit_asst = unit_row.get("assistant_trainer_profile_ids")
|
||||
if unit_asst is not None:
|
||||
src = unit_asst
|
||||
else:
|
||||
src = unit_row.get("co_trainer_ids") or []
|
||||
seen: set = set()
|
||||
out: List[int] = []
|
||||
for x in src:
|
||||
try:
|
||||
i = int(x)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if i not in seen:
|
||||
seen.add(i)
|
||||
out.append(i)
|
||||
return sorted(out)
|
||||
|
||||
|
||||
def effective_co_trainer_profile_ids_for_merge(
|
||||
unit_assistant: Any, group_co: Any
|
||||
) -> List[int]:
|
||||
"""Reine Hilfsfunktion (pytest): gleiche Semantik wie _effective_co_trainer_ids_for_row."""
|
||||
if unit_assistant is not None:
|
||||
src = unit_assistant
|
||||
else:
|
||||
src = group_co or []
|
||||
seen: set = set()
|
||||
out: List[int] = []
|
||||
for x in src:
|
||||
try:
|
||||
i = int(x)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if i not in seen:
|
||||
seen.add(i)
|
||||
out.append(i)
|
||||
return sorted(out)
|
||||
|
||||
|
||||
def _training_unit_guard_row(cur, unit_id: int) -> Dict[str, Any]:
|
||||
@@ -74,7 +149,8 @@ def _training_unit_guard_row(cur, unit_id: int) -> Dict[str, Any]:
|
||||
"""
|
||||
SELECT tu.id, tu.created_by, tu.group_id, tu.plan_template_id, tu.framework_slot_id,
|
||||
tu.lead_trainer_profile_id,
|
||||
tg.trainer_id, tg.co_trainer_ids,
|
||||
tu.assistant_trainer_profile_ids,
|
||||
tg.trainer_id, tg.co_trainer_ids, tg.club_id AS group_club_id,
|
||||
fwp.created_by AS framework_created_by
|
||||
FROM training_units tu
|
||||
LEFT JOIN training_groups tg ON tu.group_id = tg.id
|
||||
@@ -103,12 +179,12 @@ def _assert_training_unit_permission(
|
||||
return
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung")
|
||||
|
||||
co_trainers = unit_row["co_trainer_ids"] or []
|
||||
co_eff = _effective_co_trainer_ids_for_row(unit_row)
|
||||
if role not in ["admin", "superadmin"]:
|
||||
if (
|
||||
unit_row["created_by"] != profile_id
|
||||
and unit_row["trainer_id"] != profile_id
|
||||
and profile_id not in co_trainers
|
||||
and profile_id not in co_eff
|
||||
and unit_row.get("lead_trainer_profile_id") != profile_id
|
||||
):
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung")
|
||||
@@ -120,9 +196,21 @@ def _assert_delete_training_unit(role: str, created_by: int, profile_id: int) ->
|
||||
|
||||
|
||||
def _assert_club_visible_for_trainer(cur, club_id: int, profile_id: int, role: str) -> None:
|
||||
"""Nicht-Admin: mindestens eine aktive Gruppe im Verein als Trainer/Co-Trainer."""
|
||||
"""Nicht-Admin: Vereinsbezug für Listen mit club_id (Mitglied genügt; Details filtert WHERE)."""
|
||||
if role in ("admin", "superadmin"):
|
||||
return
|
||||
if can_manage_club_org(cur, profile_id, club_id, role):
|
||||
return
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT 1 FROM club_members
|
||||
WHERE club_id = %s AND profile_id = %s AND status = 'active'
|
||||
LIMIT 1
|
||||
""",
|
||||
(club_id, profile_id),
|
||||
)
|
||||
if cur.fetchone():
|
||||
return
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT 1 FROM training_groups g
|
||||
@@ -145,8 +233,9 @@ def _normalize_lead_trainer_profile_id(
|
||||
raw_lead: Any,
|
||||
profile_id: int,
|
||||
role: str,
|
||||
unit_created_by: Optional[int],
|
||||
) -> Optional[int]:
|
||||
"""NULL = Vertretung aufheben; sonst Profil-ID mit Profil-Check und Gruppenkontext."""
|
||||
"""NULL = Standard (Gruppen-Haupttrainer); sonst gültiges Profil i. d. R. mit Vereinsbezug."""
|
||||
if raw_lead is None:
|
||||
return None
|
||||
if raw_lead in ("", []):
|
||||
@@ -160,27 +249,130 @@ def _normalize_lead_trainer_profile_id(
|
||||
cur.execute("SELECT 1 FROM profiles WHERE id = %s", (nid,))
|
||||
if not cur.fetchone():
|
||||
raise HTTPException(status_code=400, detail="Profil für Leitung nicht gefunden")
|
||||
if role in ("admin", "superadmin"):
|
||||
return nid
|
||||
if nid == profile_id:
|
||||
return nid
|
||||
|
||||
cur.execute(
|
||||
"SELECT trainer_id, co_trainer_ids FROM training_groups WHERE id = %s",
|
||||
"SELECT trainer_id, co_trainer_ids, club_id FROM training_groups WHERE id = %s",
|
||||
(group_id,),
|
||||
)
|
||||
gr = cur.fetchone()
|
||||
if not gr:
|
||||
raise HTTPException(status_code=400, detail="Trainingsgruppe nicht gefunden")
|
||||
eligible = {gr["trainer_id"]} if gr.get("trainer_id") else set()
|
||||
for x in gr.get("co_trainer_ids") or []:
|
||||
eligible.add(x)
|
||||
if nid in eligible:
|
||||
return nid
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Lead-Trainer kann nur eigene Person, Haupttrainer oder Co-Trainer der Gruppe sein",
|
||||
)
|
||||
grd = dict(gr)
|
||||
cid = grd.get("club_id")
|
||||
if cid is None:
|
||||
raise HTTPException(status_code=400, detail="Trainingsgruppe nicht gefunden")
|
||||
club_i = int(cid)
|
||||
|
||||
if is_platform_admin(role):
|
||||
return nid
|
||||
|
||||
eligible = {grd["trainer_id"]} if grd.get("trainer_id") else set()
|
||||
for x in grd.get("co_trainer_ids") or []:
|
||||
try:
|
||||
eligible.add(int(x))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
|
||||
if nid == profile_id:
|
||||
if not _profile_active_in_club(cur, club_i, profile_id):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Nur aktive Vereinsmitglieder können die Leitung dieser Einheit übernehmen",
|
||||
)
|
||||
return nid
|
||||
|
||||
if nid not in eligible:
|
||||
if not _profile_active_in_club(cur, club_i, nid):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Leitung nur für Profile mit aktiver Mitgliedschaft im Verein der Gruppe",
|
||||
)
|
||||
if not _caller_may_assign_session_trainers(cur, grd, profile_id, role, unit_created_by):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Keine Berechtigung, die Leitung zuzuweisen",
|
||||
)
|
||||
return nid
|
||||
|
||||
if nid != profile_id and not _caller_may_assign_session_trainers(
|
||||
cur, grd, profile_id, role, unit_created_by
|
||||
):
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung, die Leitung anderen zuzuweisen")
|
||||
return nid
|
||||
|
||||
|
||||
def _normalize_assistant_trainer_profile_ids(
|
||||
cur,
|
||||
group_id: int,
|
||||
raw_val: Any,
|
||||
profile_id: int,
|
||||
role: str,
|
||||
unit_created_by: Optional[int],
|
||||
lead_nid: Optional[int],
|
||||
) -> Any:
|
||||
"""
|
||||
None = Vererbung aus training_groups.co_trainer_ids (SQL NULL);
|
||||
Liste = Session-Co-Trainer (JSONB Array; leeres Array ausdrücklich ohne Co.)
|
||||
"""
|
||||
if raw_val is None:
|
||||
return None
|
||||
if not isinstance(raw_val, list):
|
||||
raise HTTPException(status_code=400, detail="assistant_trainer_profile_ids muss Liste oder null sein")
|
||||
|
||||
ids_in: List[int] = []
|
||||
for x in raw_val:
|
||||
try:
|
||||
i = int(x)
|
||||
except (TypeError, ValueError):
|
||||
raise HTTPException(status_code=400, detail="assistant_trainer_profile_ids ungültig")
|
||||
if i < 1:
|
||||
raise HTTPException(status_code=400, detail="assistant_trainer_profile_ids ungültig")
|
||||
ids_in.append(i)
|
||||
uniq = sorted(set(ids_in))
|
||||
|
||||
cur.execute(
|
||||
"SELECT trainer_id, co_trainer_ids, club_id FROM training_groups WHERE id = %s",
|
||||
(group_id,),
|
||||
)
|
||||
gr = cur.fetchone()
|
||||
if not gr:
|
||||
raise HTTPException(status_code=400, detail="Trainingsgruppe nicht gefunden")
|
||||
grd = dict(gr)
|
||||
cid = grd.get("club_id")
|
||||
if cid is None:
|
||||
raise HTTPException(status_code=400, detail="Trainingsgruppe nicht gefunden")
|
||||
club_i = int(cid)
|
||||
|
||||
if not is_platform_admin(role) and not _caller_may_assign_session_trainers(
|
||||
cur, grd, profile_id, role, unit_created_by
|
||||
):
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung, Co-Trainer zuzuweisen")
|
||||
|
||||
eligible = {grd["trainer_id"]} if grd.get("trainer_id") else set()
|
||||
for x in grd.get("co_trainer_ids") or []:
|
||||
try:
|
||||
eligible.add(int(x))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
|
||||
eff_lead = lead_nid if lead_nid is not None else (grd.get("trainer_id") or None)
|
||||
|
||||
for nid in uniq:
|
||||
cur.execute("SELECT 1 FROM profiles WHERE id = %s", (nid,))
|
||||
if not cur.fetchone():
|
||||
raise HTTPException(status_code=400, detail="Profil für Co-Trainer nicht gefunden")
|
||||
if eff_lead is not None and nid == eff_lead:
|
||||
raise HTTPException(status_code=400, detail="Leitung und Co-Trainer dürfen sich nicht überschneiden")
|
||||
if is_platform_admin(role):
|
||||
continue
|
||||
if nid in eligible:
|
||||
continue
|
||||
if not _profile_active_in_club(cur, club_i, nid):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Co-Trainer nur mit aktiver Mitgliedschaft im Verein dieser Gruppe",
|
||||
)
|
||||
return uniq
|
||||
|
||||
# Nachverfolgbarkeit: Übernahmen aus Rahmenprogramm über origin_framework_slot_id
|
||||
_ORIGIN_LINEAGE_JOIN = """
|
||||
@@ -775,14 +967,18 @@ def list_training_units(
|
||||
|
||||
if gid and role not in ["admin", "superadmin"]:
|
||||
cur.execute(
|
||||
"SELECT trainer_id, co_trainer_ids FROM training_groups WHERE id = %s AND status = 'active'",
|
||||
"SELECT trainer_id, co_trainer_ids, club_id FROM training_groups WHERE id = %s AND status = 'active'",
|
||||
(gid,),
|
||||
)
|
||||
gr = cur.fetchone()
|
||||
if not gr:
|
||||
raise HTTPException(status_code=404, detail="Trainingsgruppe nicht gefunden")
|
||||
cob = gr["co_trainer_ids"] or []
|
||||
if gr["trainer_id"] != profile_id and profile_id not in cob:
|
||||
gd = dict(gr)
|
||||
cob = gd.get("co_trainer_ids") or []
|
||||
ok_staff = gd.get("trainer_id") == profile_id or profile_id in cob
|
||||
ok_org = can_manage_club_org(cur, profile_id, int(gd["club_id"]), role)
|
||||
ok_member = _profile_active_in_club(cur, int(gd["club_id"]), profile_id)
|
||||
if not (ok_staff or ok_org or ok_member):
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung für diese Gruppe")
|
||||
|
||||
order_dir = "ASC" if (sort or "").strip().lower() == "asc" else "DESC"
|
||||
@@ -805,6 +1001,8 @@ def list_training_units(
|
||||
p.name as trainer_name,
|
||||
p.name as creator_name,
|
||||
COALESCE(tu.lead_trainer_profile_id, tg.trainer_id) AS effective_lead_trainer_profile_id,
|
||||
COALESCE(tu.assistant_trainer_profile_ids, tg.co_trainer_ids, '[]'::jsonb)
|
||||
AS effective_assistant_trainer_profile_ids,
|
||||
leadp.name AS lead_trainer_name
|
||||
"""
|
||||
query += "," + _ORIGIN_LINEAGE_FIELDS
|
||||
@@ -822,10 +1020,11 @@ def list_training_units(
|
||||
|
||||
if role not in ["admin", "superadmin"]:
|
||||
where.append(
|
||||
"(tu.created_by = %s OR tg.trainer_id = %s OR "
|
||||
"(tg.co_trainer_ids IS NOT NULL AND tg.co_trainer_ids @> jsonb_build_array(%s::int)))"
|
||||
"(tu.created_by = %s OR tg.trainer_id = %s OR tu.lead_trainer_profile_id = %s OR "
|
||||
"COALESCE(tu.assistant_trainer_profile_ids, tg.co_trainer_ids, '[]'::jsonb) "
|
||||
"@> jsonb_build_array(%s::int))"
|
||||
)
|
||||
params.extend([profile_id, profile_id, profile_id])
|
||||
params.extend([profile_id, profile_id, profile_id, profile_id])
|
||||
|
||||
where.append("tu.framework_slot_id IS NULL")
|
||||
|
||||
@@ -840,7 +1039,8 @@ def list_training_units(
|
||||
if assigned_to_me:
|
||||
where.append(
|
||||
"(COALESCE(tu.lead_trainer_profile_id, tg.trainer_id) = %s OR "
|
||||
"(tg.co_trainer_ids IS NOT NULL AND tg.co_trainer_ids @> jsonb_build_array(%s::int)))"
|
||||
"COALESCE(tu.assistant_trainer_profile_ids, tg.co_trainer_ids, '[]'::jsonb) "
|
||||
"@> jsonb_build_array(%s::int))"
|
||||
)
|
||||
params.extend([profile_id, profile_id])
|
||||
|
||||
@@ -891,6 +1091,8 @@ def get_training_unit(unit_id: int, tenant: TenantContext = Depends(get_tenant_c
|
||||
tg.trainer_id AS trainer_id,
|
||||
tg.co_trainer_ids AS co_trainer_ids,
|
||||
COALESCE(tu.lead_trainer_profile_id, tg.trainer_id) AS effective_lead_trainer_profile_id,
|
||||
COALESCE(tu.assistant_trainer_profile_ids, tg.co_trainer_ids, '[]'::jsonb)
|
||||
AS effective_assistant_trainer_profile_ids,
|
||||
leadp.name AS lead_trainer_name,
|
||||
""" + _ORIGIN_LINEAGE_FIELDS.strip() + """
|
||||
FROM training_units tu
|
||||
@@ -957,27 +1159,77 @@ def create_training_unit(data: dict, tenant: TenantContext = Depends(get_tenant_
|
||||
tpl_id_safe = plan_template_id
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO training_units (
|
||||
group_id, planned_date, planned_time_start, planned_time_end,
|
||||
planned_focus, status, notes, trainer_notes, created_by,
|
||||
plan_template_id
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING id
|
||||
""",
|
||||
(
|
||||
group_id,
|
||||
planned_date,
|
||||
data.get("planned_time_start"),
|
||||
data.get("planned_time_end"),
|
||||
data.get("planned_focus"),
|
||||
data.get("status", "planned"),
|
||||
data.get("notes"),
|
||||
data.get("trainer_notes"),
|
||||
profile_id,
|
||||
tpl_id_safe,
|
||||
),
|
||||
"SELECT trainer_id FROM training_groups WHERE id = %s",
|
||||
(int(group_id),),
|
||||
)
|
||||
g0 = cur.fetchone()
|
||||
default_group_trainer = g0["trainer_id"] if g0 else None
|
||||
|
||||
lead_ins: Optional[int] = None
|
||||
if "lead_trainer_profile_id" in data:
|
||||
lead_ins = _normalize_lead_trainer_profile_id(
|
||||
cur,
|
||||
int(group_id),
|
||||
data.get("lead_trainer_profile_id"),
|
||||
profile_id,
|
||||
role,
|
||||
profile_id,
|
||||
)
|
||||
assistant_val: Any = None
|
||||
assistant_set = False
|
||||
if "assistant_trainer_profile_ids" in data:
|
||||
assistant_set = True
|
||||
eff_lead_for_co = lead_ins if lead_ins is not None else default_group_trainer
|
||||
assistant_val = _normalize_assistant_trainer_profile_ids(
|
||||
cur,
|
||||
int(group_id),
|
||||
data.get("assistant_trainer_profile_ids"),
|
||||
profile_id,
|
||||
role,
|
||||
profile_id,
|
||||
eff_lead_for_co,
|
||||
)
|
||||
|
||||
base_params = (
|
||||
group_id,
|
||||
planned_date,
|
||||
data.get("planned_time_start"),
|
||||
data.get("planned_time_end"),
|
||||
data.get("planned_focus"),
|
||||
data.get("status", "planned"),
|
||||
data.get("notes"),
|
||||
data.get("trainer_notes"),
|
||||
profile_id,
|
||||
tpl_id_safe,
|
||||
lead_ins,
|
||||
)
|
||||
if assistant_set:
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO training_units (
|
||||
group_id, planned_date, planned_time_start, planned_time_end,
|
||||
planned_focus, status, notes, trainer_notes, created_by,
|
||||
plan_template_id,
|
||||
lead_trainer_profile_id,
|
||||
assistant_trainer_profile_ids
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING id
|
||||
""",
|
||||
base_params + (assistant_val,),
|
||||
)
|
||||
else:
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO training_units (
|
||||
group_id, planned_date, planned_time_start, planned_time_end,
|
||||
planned_focus, status, notes, trainer_notes, created_by,
|
||||
plan_template_id,
|
||||
lead_trainer_profile_id
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING id
|
||||
""",
|
||||
base_params,
|
||||
)
|
||||
|
||||
unit_id = cur.fetchone()["id"]
|
||||
|
||||
@@ -1066,8 +1318,13 @@ def update_training_unit(unit_id: int, data: dict, tenant: TenantContext = Depen
|
||||
tuple(blueprint_params),
|
||||
)
|
||||
else:
|
||||
cur_lead = unit_row.get("lead_trainer_profile_id")
|
||||
base_tr = unit_row.get("trainer_id")
|
||||
lead_sql = ""
|
||||
lead_params: List[Any] = []
|
||||
assist_sql = ""
|
||||
assist_params: List[Any] = []
|
||||
nl: Optional[int]
|
||||
if "lead_trainer_profile_id" in data:
|
||||
nl = _normalize_lead_trainer_profile_id(
|
||||
cur,
|
||||
@@ -1075,9 +1332,27 @@ def update_training_unit(unit_id: int, data: dict, tenant: TenantContext = Depen
|
||||
data.get("lead_trainer_profile_id"),
|
||||
profile_id,
|
||||
role,
|
||||
unit_row.get("created_by"),
|
||||
)
|
||||
lead_sql = ", lead_trainer_profile_id = %s"
|
||||
lead_params.append(nl)
|
||||
eff_lead_for_co = nl if nl is not None else base_tr
|
||||
else:
|
||||
nl = cur_lead if cur_lead is not None else base_tr
|
||||
eff_lead_for_co = nl
|
||||
|
||||
if "assistant_trainer_profile_ids" in data:
|
||||
na = _normalize_assistant_trainer_profile_ids(
|
||||
cur,
|
||||
unit_row["group_id"],
|
||||
data.get("assistant_trainer_profile_ids"),
|
||||
profile_id,
|
||||
role,
|
||||
unit_row.get("created_by"),
|
||||
eff_lead_for_co,
|
||||
)
|
||||
assist_sql = ", assistant_trainer_profile_ids = %s"
|
||||
assist_params.append(na)
|
||||
|
||||
cur.execute(
|
||||
f"""
|
||||
@@ -1096,6 +1371,7 @@ def update_training_unit(unit_id: int, data: dict, tenant: TenantContext = Depen
|
||||
plan_template_id = COALESCE(%s, plan_template_id),
|
||||
updated_at = NOW()
|
||||
{lead_sql}
|
||||
{assist_sql}
|
||||
WHERE id = %s
|
||||
""",
|
||||
(
|
||||
@@ -1113,6 +1389,7 @@ def update_training_unit(unit_id: int, data: dict, tenant: TenantContext = Depen
|
||||
tpl_id_val,
|
||||
)
|
||||
+ tuple(lead_params)
|
||||
+ tuple(assist_params)
|
||||
+ (unit_id,),
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user