Enhance Exercise Management and AI Integration
Test Suite / playwright-tests (push) Waiting to run
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Failing after 1s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Has been cancelled

- Updated the exercise form to include a tabbed navigation structure, improving user experience with sections for Stammdaten, Anleitung, Einordnung, Varianten, and Medien & Mehr.
- Introduced the concept of **Freigabelevel** (visibility level) in the UI, replacing previous terminology for clarity and consistency across components.
- Implemented new AI endpoints for exercise suggestions and regeneration, allowing for dynamic content generation without direct database writes.
- Removed the legacy `is_primary` flag from exercise skills in the UI, ensuring that intensity levels (`niedrig`, `mittel`, `hoch`) are the primary focus for skill management.
- Enhanced the variant management process with improved saving mechanisms and UI updates to reflect changes more intuitively.
This commit is contained in:
Lars committed 2026-05-22 07:52:31 +02:00
1 parent 7245bbb1da
commit e4451e1362
25 files changed
+1240 -78

No files matched your search

+108 -1
View File
@@ -35,6 +35,8 @@ from tenant_context import TenantContext, get_tenant_context, get_tenant_context
from media_storage import get_effective_media_root, library_storage_key, path_under_media_root
from media_rights import assert_rights_for_exercise_link, validate_rights_declaration, write_rights_declaration, update_rights_quick_fields
from media_legal_hold import assert_not_under_legal_hold
from exercise_ai import run_exercise_ai_suggestion
from exercise_rich_text import (
RICH_HTML_EXERCISE_FIELDS,
assert_no_inline_media_references_on_create,
@@ -356,6 +358,42 @@ class ExerciseMediaFromAsset(BaseModel):
media_type: Optional[str] = None
class ExerciseAiSuggestBody(BaseModel):
title: Optional[str] = Field(None, max_length=300)
goal: Optional[str] = Field(None, max_length=64000)
execution: Optional[str] = Field(None, max_length=128000)
focus_area_hint: Optional[str] = Field(None, max_length=1200)
include_summary: bool = True
include_skills: bool = True
@model_validator(mode="after")
def check_include_any(self):
if not self.include_summary and not self.include_skills:
raise ValueError("Mindestens include_summary oder include_skills aktivieren.")
return self
class ExerciseAiRegenerateBody(BaseModel):
"""Welche Artefakte neu angefragt werden sollen."""
regenerate: list[str] = Field(default_factory=lambda: ["summary", "skills"])
@model_validator(mode="after")
def normalize_regs(self):
allowed = {"summary", "skills"}
raw = [str(x).strip().lower() for x in (self.regenerate or [])]
out = []
seen = set()
for lx in raw:
if lx in allowed and lx not in seen:
out.append(lx)
seen.add(lx)
if not out:
out = ["summary", "skills"]
self.regenerate = out
return self
class ExerciseVariantCreate(BaseModel):
variant_name: str = Field(..., min_length=3, max_length=200)
description: Optional[str] = None
@@ -1244,7 +1282,7 @@ def assign_exercise_relations(
(
exercise_id,
skill["skill_id"],
False,
bool(skill.get("is_primary")),
normalize_exercise_skill_intensity(skill.get("intensity")),
normalize_exercise_skill_level(skill.get("required_level")),
normalize_exercise_skill_level(skill.get("target_level")),
@@ -2216,6 +2254,75 @@ def list_exercises_like_get(
)
def _focus_area_hint_from_detail(exercise: Dict[str, Any]) -> str:
parts: List[str] = []
for row in exercise.get("focus_areas") or []:
if isinstance(row, dict):
nm = (row.get("name") or "").strip()
if nm:
parts.append(nm)
txt = ", ".join(parts).strip()
if len(txt) > 900:
return txt[:899] + "…"
return txt
@router.post("/exercises/ai/suggest")
def exercise_ai_suggest_endpoint(
body: ExerciseAiSuggestBody,
tenant: TenantContext = Depends(get_tenant_context),
):
"""
KI-Vorschlaege (Kurzfassung und/oder Skill-Zuordnung) ohne Speichern.
OPENROUTER_API_KEY erforderlich.
"""
_ = tenant.profile_id
with get_db() as conn:
cur = get_cursor(conn)
payload = run_exercise_ai_suggestion(
cur,
title=(body.title or "").strip(),
goal=body.goal,
execution=body.execution,
focus_area_hint=(body.focus_area_hint or "").strip() or None,
want_summary=body.include_summary,
want_skills=body.include_skills,
)
return payload
@router.post("/exercises/{exercise_id}/ai/regenerate")
def exercise_ai_regenerate_endpoint(
exercise_id: int,
body: ExerciseAiRegenerateBody,
tenant: TenantContext = Depends(get_tenant_context),
):
"""Neu-Anfrage KI fuer eine gespeicherte Uebung; schreibendes Ergebnis nur im Frontend (PUT)."""
want_summary = "summary" in body.regenerate
want_skills = "skills" in body.regenerate
with get_db() as conn:
cur = get_cursor(conn)
_assert_can_edit_exercise(cur, exercise_id, tenant)
exercise = enrich_exercise_detail(exercise_id, cur)
if not exercise:
raise HTTPException(status_code=404, detail="Übung nicht gefunden")
focus = _focus_area_hint_from_detail(exercise)
payload = run_exercise_ai_suggestion(
cur,
title=str(exercise.get("title") or "").strip(),
goal=exercise.get("goal"),
execution=exercise.get("execution"),
focus_area_hint=focus or None,
want_summary=want_summary,
want_skills=want_skills,
)
return payload
@router.get("/exercises/{exercise_id}")
def get_exercise(
exercise_id: int,