Skip to content

Commit 2461197

Browse files
committed
Conditional publishing of QTI archives instead of perseus.
1 parent f7d1da8 commit 2461197

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

contentcuration/contentcuration/utils/publish.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from contentcuration import models as ccmodels
4545
from contentcuration.decorators import delay_user_storage_calculation
4646
from contentcuration.utils.assessment.perseus import PerseusExerciseGenerator
47+
from contentcuration.utils.assessment.qti.archive import QTIExerciseGenerator
4748
from contentcuration.utils.cache import delete_public_channel_cache_keys
4849
from contentcuration.utils.files import create_thumbnail_from_base64
4950
from contentcuration.utils.files import get_thumbnail_encoding
@@ -320,12 +321,33 @@ def recurse_nodes(self, node, inherited_fields): # noqa C901
320321

321322
if node.kind_id == content_kinds.EXERCISE:
322323
exercise_data = process_assessment_metadata(node, kolibrinode)
324+
any_free_response = any(
325+
t == exercises.FREE_RESPONSE
326+
for t in exercise_data["assessment_mapping"].values()
327+
)
328+
generator_class = (
329+
QTIExerciseGenerator
330+
if any_free_response
331+
else PerseusExerciseGenerator
332+
)
333+
334+
# If this exercise previously had a file generated by a different
335+
# generator, make sure we clean it up here.
336+
stale_presets = {
337+
PerseusExerciseGenerator.preset,
338+
QTIExerciseGenerator.preset,
339+
} - {generator_class.preset}
340+
341+
# Remove archives produced by the previously-used generator
342+
node.files.filter(preset_id__in=stale_presets).delete()
343+
323344
if (
324345
self.force_exercises
325346
or node.changed
326-
or not node.files.filter(preset_id=format_presets.EXERCISE).exists()
347+
or not node.files.filter(preset_id=generator_class.preset).exists()
327348
):
328-
generator = PerseusExerciseGenerator(
349+
350+
generator = generator_class(
329351
node,
330352
exercise_data,
331353
self.channel_id,

0 commit comments

Comments
 (0)