feat(exercises): implement inline media support in exercise content
Deploy Development / deploy (push) Successful in 37s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
Deploy Development / deploy (push) Successful in 37s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
- Added functionality for inline media references in exercise text using `{{exerciseMedia:id}}` syntax, which normalizes to a canonical `<span>` element.
- Updated the frontend to utilize `ExerciseRichTextBlock` for rendering exercise content, allowing for embedded media display.
- Enhanced the Rich Text Editor to support inserting inline media placeholders.
- Version bump to 0.8.60 to reflect these changes in media handling and exercise content management.
This commit is contained in:
1 parent
f745e5d082
commit
cc51b0f08f
17 files changed
+655
-149
No files matched your search
@@ -29,6 +29,13 @@ from club_tenancy import (
|
||||
)
|
||||
from tenant_context import TenantContext, get_tenant_context, get_tenant_context_flexible, library_content_visibility_sql
|
||||
from media_storage import get_effective_media_root, library_storage_key, path_under_media_root
|
||||
from exercise_rich_text import (
|
||||
RICH_HTML_EXERCISE_FIELDS,
|
||||
assert_no_inline_media_references_on_create,
|
||||
collect_inline_exercise_media_ids,
|
||||
normalize_inline_exercise_media_markup,
|
||||
validate_inline_exercise_media_ids_for_exercise,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -1812,6 +1819,16 @@ def create_exercise(
|
||||
if body.visibility == "club" and club_id is None:
|
||||
club_id = tenant.effective_club_id
|
||||
|
||||
# §11 Inline-Medien: Kurzsyntax → kanonisches Markup; Verweise erst nach Medien-Anlage möglich
|
||||
create_ids: set[int] = set()
|
||||
for fld in sorted(RICH_HTML_EXERCISE_FIELDS):
|
||||
raw_html = getattr(body, fld, None)
|
||||
if raw_html:
|
||||
normed = normalize_inline_exercise_media_markup(raw_html)
|
||||
setattr(body, fld, normed)
|
||||
create_ids |= collect_inline_exercise_media_ids(normed or "")
|
||||
assert_no_inline_media_references_on_create(create_ids)
|
||||
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
assert_valid_governance_visibility(
|
||||
@@ -1868,16 +1885,25 @@ def update_exercise(
|
||||
cur = get_cursor(conn)
|
||||
|
||||
cur.execute(
|
||||
"SELECT created_by, visibility, club_id FROM exercises WHERE id = %s",
|
||||
f"""SELECT created_by, visibility, club_id,
|
||||
{", ".join(sorted(RICH_HTML_EXERCISE_FIELDS))}
|
||||
FROM exercises WHERE id = %s""",
|
||||
(exercise_id,),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Übung nicht gefunden")
|
||||
|
||||
rd_full = r2d(row)
|
||||
rich_row = {fld: rd_full.get(fld) for fld in RICH_HTML_EXERCISE_FIELDS}
|
||||
|
||||
_assert_can_edit_exercise(cur, exercise_id, tenant)
|
||||
|
||||
rd = r2d(row)
|
||||
rd = {
|
||||
"created_by": rd_full.get("created_by"),
|
||||
"visibility": rd_full.get("visibility"),
|
||||
"club_id": rd_full.get("club_id"),
|
||||
}
|
||||
ex_vis = (rd.get("visibility") or "private").strip().lower()
|
||||
ex_cid = rd.get("club_id")
|
||||
if ex_cid is not None:
|
||||
@@ -1888,6 +1914,23 @@ def update_exercise(
|
||||
promote_media_flag = raw_promo is True
|
||||
default_official_copy = data.pop("default_official_media_copyright", None)
|
||||
|
||||
merged_rich = {fld: rich_row.get(fld) for fld in RICH_HTML_EXERCISE_FIELDS}
|
||||
for fld in RICH_HTML_EXERCISE_FIELDS:
|
||||
if fld not in data:
|
||||
continue
|
||||
raw_v = data[fld]
|
||||
if raw_v is None:
|
||||
merged_rich[fld] = None
|
||||
continue
|
||||
if isinstance(raw_v, str):
|
||||
nv = normalize_inline_exercise_media_markup(raw_v)
|
||||
data[fld] = nv
|
||||
merged_rich[fld] = nv
|
||||
inline_union: set[int] = set()
|
||||
for val in merged_rich.values():
|
||||
inline_union |= collect_inline_exercise_media_ids(val if isinstance(val, str) else None)
|
||||
validate_inline_exercise_media_ids_for_exercise(cur, exercise_id, inline_union)
|
||||
|
||||
next_vis = ex_vis
|
||||
if "visibility" in data and data["visibility"] is not None:
|
||||
v_raw = str(data["visibility"]).strip().lower()
|
||||
@@ -2064,7 +2107,11 @@ def create_exercise_variant(
|
||||
seq = cur.fetchone()["n"]
|
||||
|
||||
desc = (body.description or "").strip() or None
|
||||
exec_ch = (body.execution_changes or "").strip() or None
|
||||
exec_ch_raw = (body.execution_changes or "").strip() or None
|
||||
exec_ch = normalize_inline_exercise_media_markup(exec_ch_raw) if exec_ch_raw else None
|
||||
if exec_ch:
|
||||
v_ids = collect_inline_exercise_media_ids(exec_ch)
|
||||
validate_inline_exercise_media_ids_for_exercise(cur, exercise_id, v_ids)
|
||||
diff = (body.difficulty_adjustment or "").strip() or None
|
||||
|
||||
cur.execute(
|
||||
@@ -2118,7 +2165,13 @@ def update_exercise_variant(
|
||||
if "description" in data:
|
||||
old["description"] = (data["description"] or "").strip() or None
|
||||
if "execution_changes" in data:
|
||||
old["execution_changes"] = (data["execution_changes"] or "").strip() or None
|
||||
ec_raw = (data["execution_changes"] or "").strip() or None
|
||||
ec_norm = normalize_inline_exercise_media_markup(ec_raw) if ec_raw else None
|
||||
if ec_norm:
|
||||
validate_inline_exercise_media_ids_for_exercise(
|
||||
cur, exercise_id, collect_inline_exercise_media_ids(ec_norm)
|
||||
)
|
||||
old["execution_changes"] = ec_norm
|
||||
if "duration_min" in data:
|
||||
old["duration_min"] = data["duration_min"]
|
||||
if "duration_max" in data:
|
||||
|
||||
Reference in new issue
Block a user