Update version to 0.8.146 and implement publish-to-framework feature for training units
Deploy Development / deploy (push) Successful in 49s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m19s

- Incremented app version to 0.8.146 and updated build date to 2026-05-19.
- Added new API endpoint to publish training units as session blueprints to framework programs.
- Introduced frontend functionality to support publishing training units, including a modal for user interaction.
- Updated changelog to reflect the new feature and its associated changes.
This commit is contained in:
Lars committed 2026-05-19 08:51:48 +02:00
1 parent 623af621b4
commit 7693139242
6 files changed
+770 -4

No files matched your search

+308
View File
@@ -878,6 +878,86 @@ def _phases_clone_payload(cur, unit_id: int) -> List[Dict[str, Any]]:
return out
def _copy_scheduled_unit_plan_to_blueprint(
cur,
source_unit_id: int,
blueprint_unit_id: int,
profile_id: int,
role: str,
) -> None:
"""Übernimmt Phasen/Sektionen einer geplanten Einheit in eine Rahmen-Blueprint-Einheit."""
cloned_phases = _phases_clone_payload(cur, source_unit_id)
if cloned_phases:
_replace_unit_phases(cur, blueprint_unit_id, cloned_phases, profile_id, role, profile_id)
return
secs = _fetch_sections(cur, source_unit_id)
sections_payload = [_clone_section_payload_dict(s) for s in secs]
if not sections_payload:
_replace_unit_sections(
cur,
blueprint_unit_id,
[{"title": "Ablauf", "order_index": 0, "guidance_notes": None, "items": []}],
)
return
_replace_unit_sections(cur, blueprint_unit_id, sections_payload)
def _shift_framework_slots_sort_orders_from(cur, framework_program_id: int, from_sort_order: int) -> None:
cur.execute(
"""
UPDATE training_framework_slots
SET sort_order = sort_order + 1
WHERE framework_program_id = %s AND sort_order >= %s
""",
(framework_program_id, int(from_sort_order)),
)
def _insert_framework_slot_and_blueprint_unit(
cur,
framework_program_id: int,
sort_order: int,
title: Optional[str],
notes: Optional[Any],
profile_id: int,
) -> Tuple[int, int]:
"""Legt Slot-Zeile + Blueprint-`training_units`-Zeile an; gibt (slot_id, blueprint_unit_id) zurück."""
cur.execute(
"""
INSERT INTO training_framework_slots (
framework_program_id, sort_order, title, notes, training_unit_id
) VALUES (%s, %s, %s, %s, NULL)
RETURNING id
""",
(
framework_program_id,
int(sort_order),
title,
notes,
),
)
sid = int(cur.fetchone()["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, framework_slot_id
) VALUES (
NULL, NULL,
NULL, NULL, NULL,
'planned', NULL, NULL,
%s, NULL, %s
)
RETURNING id
""",
(profile_id, sid),
)
bid = int(cur.fetchone()["id"])
return sid, bid
def _copy_blueprint_into_scheduled_unit(
cur,
blueprint_unit_id: int,
@@ -2877,6 +2957,234 @@ def create_training_unit_from_framework_slot(data: dict, tenant: TenantContext =
return get_training_unit(new_id, tenant)
@router.post("/training-units/{unit_id}/publish-to-framework")
def publish_training_unit_to_framework(
unit_id: int, data: dict, tenant: TenantContext = Depends(get_tenant_context)
):
"""Geplanten Ablauf einer Einheit als Session-Blueprint in ein Rahmenprogramm übernehmen (neu / bestehend, Slot wählbar)."""
from routers.training_framework_programs import ( # noqa: WPS433 — zyklischer Import
_assert_visibility,
_fetch_framework_row,
_insert_goal_rows,
_parse_positive_int_ids,
_replace_target_groups,
_replace_training_types,
_response_framework_detail,
)
profile_id = tenant.profile_id
role = tenant.global_role
if not _has_planning_role(role):
raise HTTPException(status_code=403, detail="Nur Planungsberechtigte dürfen Rahmenprogramme bearbeiten")
mode = (data.get("mode") or "").strip().lower()
if mode not in ("new_slot", "existing_slot"):
raise HTTPException(status_code=400, detail="mode muss new_slot oder existing_slot sein")
fw_new = data.get("new_framework")
fw_id_raw = data.get("framework_program_id")
has_new = isinstance(fw_new, dict) and len(fw_new) > 0
has_id = fw_id_raw not in (None, "")
if has_new == has_id:
raise HTTPException(
status_code=400,
detail="Entweder new_framework ODER framework_program_id angeben (nicht beides, nicht keines)",
)
framework_id: int = 0
slot_title_o: Optional[str] = None
notes_o = data.get("slot_notes")
st = data.get("slot_title")
if st is not None:
st = str(st).strip()
slot_title_o = st or None
with get_db() as conn:
cur = get_cursor(conn)
unit_row = _training_unit_guard_row(cur, unit_id)
if unit_row.get("framework_slot_id"):
raise HTTPException(
status_code=400,
detail="Nur geplante Einheiten (Kalender) können in einen Rahmen übernommen werden, keine Blueprint-Einheit",
)
_assert_training_unit_permission(cur, unit_row, profile_id, role)
if has_new:
title = (fw_new.get("title") or "").strip()
if not title:
raise HTTPException(status_code=400, detail="new_framework.title ist Pflicht")
vis = _assert_visibility(fw_new.get("visibility") or "private")
club_nf = fw_new.get("club_id")
if club_nf in ("", []):
club_nf = None
if vis == "club" and club_nf is None:
club_nf = tenant.effective_club_id
goals_in = fw_new.get("goals")
if not isinstance(goals_in, list) or not goals_in:
raise HTTPException(
status_code=400,
detail="new_framework.goals als Liste mit mindestens einem Eintrag ist Pflicht",
)
fa_id = _optional_positive_int(fw_new.get("focus_area_id"), "focus_area_id")
sd_id = _optional_positive_int(fw_new.get("style_direction_id"), "style_direction_id")
tt_ids = _parse_positive_int_ids(fw_new.get("training_type_ids"), "training_type_ids")
tg_ids = _parse_positive_int_ids(fw_new.get("target_group_ids"), "target_group_ids")
assert_valid_governance_visibility(cur, profile_id, role, vis, club_nf)
cur.execute(
"""
INSERT INTO training_framework_programs (
title, description,
planned_period_start, planned_period_end,
visibility, club_id, created_by,
focus_area_id, style_direction_id
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
RETURNING id
""",
(
title[:200],
fw_new.get("description"),
fw_new.get("planned_period_start"),
fw_new.get("planned_period_end"),
vis,
club_nf,
profile_id,
fa_id,
sd_id,
),
)
framework_id = int(cur.fetchone()["id"])
_insert_goal_rows(cur, framework_id, goals_in)
_replace_training_types(cur, framework_id, tt_ids)
_replace_target_groups(cur, framework_id, tg_ids)
else:
try:
framework_id = int(fw_id_raw)
except (TypeError, ValueError):
raise HTTPException(status_code=400, detail="framework_program_id ungültig") from None
if framework_id < 1:
raise HTTPException(status_code=400, detail="framework_program_id ungültig")
row_fw = _fetch_framework_row(cur, framework_id)
assert_library_content_editable(cur, profile_id, role, row_fw)
ins_raw = data.get("insert_at_index")
slot_id_out: int = 0
if mode == "new_slot":
pos: Optional[int] = None
if ins_raw is not None and ins_raw != "":
try:
pos = int(ins_raw)
except (TypeError, ValueError):
raise HTTPException(status_code=400, detail="insert_at_index ungültig") from None
if pos < 0:
raise HTTPException(status_code=400, detail="insert_at_index ungültig")
if pos is None:
cur.execute(
"""
SELECT COALESCE(MAX(sort_order), -1) + 1 AS n
FROM training_framework_slots
WHERE framework_program_id = %s
""",
(framework_id,),
)
pos = int(cur.fetchone()["n"])
else:
cur.execute(
"SELECT COUNT(*)::int AS c FROM training_framework_slots WHERE framework_program_id = %s",
(framework_id,),
)
cmax = int(cur.fetchone()["c"])
if pos > cmax:
pos = cmax
_shift_framework_slots_sort_orders_from(cur, framework_id, pos)
sid, bid = _insert_framework_slot_and_blueprint_unit(
cur,
framework_id,
pos,
slot_title_o,
notes_o,
profile_id,
)
slot_id_out = sid
_copy_scheduled_unit_plan_to_blueprint(cur, unit_id, bid, profile_id, role)
_promote_private_exercises_used_in_unit(cur, bid, profile_id, role)
else:
raw_existing = data.get("framework_slot_id")
try:
slot_id_out = int(raw_existing)
except (TypeError, ValueError):
raise HTTPException(status_code=400, detail="framework_slot_id ist Pflicht und muss eine Zahl sein") from None
if slot_id_out < 1:
raise HTTPException(status_code=400, detail="framework_slot_id ist ungültig")
cur.execute(
"""
SELECT id, framework_program_id, sort_order, title, notes
FROM training_framework_slots
WHERE id = %s
""",
(slot_id_out,),
)
slot_row = cur.fetchone()
if not slot_row:
raise HTTPException(status_code=404, detail="Rahmen-Slot nicht gefunden")
if int(slot_row["framework_program_id"]) != framework_id:
raise HTTPException(status_code=400, detail="Slot gehört nicht zu diesem Rahmenprogramm")
cur.execute(
"SELECT id FROM training_units WHERE framework_slot_id = %s",
(slot_id_out,),
)
bp = cur.fetchone()
if not bp:
raise HTTPException(status_code=404, detail="Keine Blueprint-Einheit für diesen Slot")
meta_fields: List[str] = []
meta_params: List[Any] = []
if "slot_title" in data:
stn = data.get("slot_title")
title_v = (str(stn).strip() or None) if stn is not None else None
meta_fields.append("title = %s")
meta_params.append(title_v)
if "slot_notes" in data:
meta_fields.append("notes = %s")
meta_params.append(data.get("slot_notes"))
if meta_fields:
meta_params.append(slot_id_out)
cur.execute(
f"""
UPDATE training_framework_slots
SET {", ".join(meta_fields)}
WHERE id = %s
""",
tuple(meta_params),
)
bid = int(bp["id"])
_copy_scheduled_unit_plan_to_blueprint(cur, unit_id, bid, profile_id, role)
_promote_private_exercises_used_in_unit(cur, bid, profile_id, role)
cur.execute(
"UPDATE training_framework_programs SET updated_at = NOW() WHERE id = %s",
(framework_id,),
)
conn.commit()
return _response_framework_detail(framework_id, profile_id, role)
@router.post("/training-units/quick-create")
def quick_create_training_unit(data: dict, tenant: TenantContext = Depends(get_tenant_context)):
profile_id = tenant.profile_id
+11 -4
View File
@@ -1,7 +1,7 @@
# Shinkan Jinkendo Version Information
APP_VERSION = "0.8.145"
BUILD_DATE = "2026-05-16"
APP_VERSION = "0.8.146"
BUILD_DATE = "2026-05-19"
DB_SCHEMA_VERSION = "20260516065"
MODULE_VERSIONS = {
@@ -22,9 +22,9 @@ MODULE_VERSIONS = {
"skills": "0.1.1", # DB 065 karate_relevance + relevance_level; CRUD unterstützt Felder
"methods": "0.1.0",
"exercises": "2.28.0", # GET /api/exercises Keyset cursor_updated_at + cursor_id; Sortierung id als Tie-break
"training_units": "0.3.0", # GET /api/training-units Keyset cursor_planned_date + cursor_id (+ optional cursor_planned_time); Sort mit id-Tiebreak
"training_units": "0.4.0", # POST .../publish-to-framework: Ablauf aus geplanter Einheit → Rahmen-Slot-Blueprint
"training_programs": "0.1.0",
"planning": "0.13.0", # Vorlagen/Framework/Module/Graphs: RBAC wie Übungen (edit/delete/governance transition); Planungs-UI Sichtbarkeit neue Vorlage
"planning": "0.14.0", # publish-to-framework; UI Rahmen-Session aus Planung
"dashboard": "1.1.0", # GET /api/dashboard/kpis inkl. training_home (ein Client-Roundtrip für KPIs + nächste Termine)
"training_modules": "1.1.0", # PUT/DELETE: assert_library_content_* (Vereinsadmin löscht Vereins-Inhalt, Trainer bearbeitet club wie Übungen)
"import_wiki": "1.0.3", # Default-Kategorie Fähigkeiten: Fähigkeitsbeschreibung; cmtitle-Normalisierung; UI Preview/Execute Defaults je Typ
@@ -36,6 +36,13 @@ MODULE_VERSIONS = {
}
CHANGELOG = [
{
"version": "0.8.146",
"date": "2026-05-19",
"changes": [
"Planung: Trainingseinheit → Rahmenprogramm (Session-Slot) speichern; API POST /api/training-units/{id}/publish-to-framework",
],
},
{
"version": "0.8.145",
"date": "2026-05-16",