[QTI] Use File.included_presets for more comprehensive import renderability gating
Overview
Evolve Kolibri's renderable filter to honor File.included_presets (learningequality/studio#6004), so a node imports only when some file's required presets are all locally renderable.
Complexity: Medium Target branch: develop
Context
renderable_contentnodes_q_filter(content_types_tools.py) isQ(kind=TOPIC) | OR(Q(files__preset=p) for p in installed renderers' presets)— a node is renderable if any file's own preset is renderable. It can't express a file that needs more than one renderer.- Studio publishes
File.included_presets, a bitmask of every preset a file needs — its own (learningequality/studio#6004) plus embedded (theqti | exercisemixed-file rule, learningequality/studio#6006). - A mixed Perseus-in-QTI file needs both
qtiandexercise; the OR-of-own-preset filter would wrongly import it where only the QTI renderer is installed.
The Change
- Bump le-utils to 0.2.18 (
pyproject.toml, currently0.2.17); it addsRENDERABLE_PRESETS_ORDERinle_utils/constants/format_presets.py. - Derive every preset bit from that list:
bit = 2 ** RENDERABLE_PRESETS_ORDER.index(preset). It is append-only; Kolibri defines no ordering of its own. - Build the available-presets bitmask by ORing the bits of every preset across installed
ContentRendererHook.presets. - Add
included_presetsto the contentFilemodel as a nullable integer bitmask with no default. - No default keeps the add-column migration metadata-only (a default rewrites the table on older Postgres).
- Bump the content DB schema version (V5 → V6).
- Replace the renderable filter: a node is renderable if
kind=TOPIC, or any file hasincluded_presets IS NOT NULL AND included_presets & ~available == 0.NULLreads as a subset of nothing and never qualifies.
Populating included_presets for pre-V6 data
included_presets is published only on V6 channel databases (learningequality/studio#6004). Backfill every File that predates it — imported from a ≤V5 channel DB, or already local before the column existed:
Set the bit for the file's own preset when
preset in RENDERABLE_PRESETS_ORDER; leaveNULLotherwise (supplementary files need no renderer).
This reproduces today's single-preset gating. No file is ever stored as 0 — renderable files set ≥1 bit, others stay NULL — so the filter's IS NOT NULL needs no zero-guard.
Older channel-DB imports (schema ≤ V5), in channel_import.py:
- Register
VERSION_6: ChannelImport(naive one-to-one). - A ≤V5 source lacks the column, so import leaves
included_presetsNULL. - Add
NoIncludedPresetsChannelImport(ChannelImport)with a Filepostopset_included_presets_from_preset— shape ofset_learning_activities_from_kind: per-presetUPDATE file SET included_presets=? WHERE preset=? AND channel_id=?. - Have
NoLearningActivitiesChannelImportextend it, so V1–V5 and older inherit the backfill. MIN_CONTENT_SCHEMA_VERSIONstays V5.
Existing local DB:
- Backfill via a Kolibri upgrade task in
kolibri/core/content/upgrade.py—@version_upgrade(old_version="<0.20.0"), pattern ofcontentnode_modality_annotation_update. - Apply the same rule across the whole
Filetable. - Use the upgrade task, not a data migration.
Acceptance Criteria
- [ ] A mixed Perseus-in-QTI node imports only where both the
qtiandexerciserenderers are installed - [ ] It is gated out where the
exerciserenderer is absent - [ ] A dual-published node (separate qti and perseus files) imports where either renderer is installed
- [ ] Existing single-preset content gates exactly as today
- [ ] Tests cover the mixed (all-of-a-file's-presets) and dual-publish (any-file) cases
- [ ] le-utils bumped to 0.2.18; all bit math derives from
RENDERABLE_PRESETS_ORDER - [ ]
included_presetsis nullable with no default; the add-column migration is metadata-only - [ ] A file with
NULLincluded_presets(unbackfilled or supplementary) never makes its node renderable - [ ] Importing a schema-≤V5 channel backfills
included_presetsfrom each file's preset; gating unchanged from today - [ ] The upgrade task backfills
included_presetsfor File rows imported before the column existed - [ ] Tests cover both backfill paths (channel import + upgrade task) and the
NULLgating
References
- kolibri#11428 — Allow Kolibri to render QTI assessments
AI usage
Architecture decided with the maintainer across an iterative session: blanket
QTItype with the item XML inraw_data; XSD-authoritative validation across all sources; a legacy→QTI global migration with an API-layer dual-read; ricecooker upload delegating to the AssessmentItem serializer; and a Perseus custom-interaction contract confirmed against the QTI 3.0 specification. Claude mapped the existing publish/validation/ricecooker code, proposed the breakdown, and drafted each issue; the maintainer steered every decision and reviewed throughout.
Hi @rtibbles , Can I work on this issues?
Hi! 👋
Thanks so much for your interest! This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues. If there are no unassigned 'help wanted' issues available, please wait until new ones are added.
We really appreciate your willingness to help. 😊
Are you preparing for Google Summer of Code? See our GSoC guidelines.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
Fixed in #14994