|
44 | 44 | from contentcuration import models as ccmodels
|
45 | 45 | from contentcuration.decorators import delay_user_storage_calculation
|
46 | 46 | from contentcuration.utils.assessment.perseus import PerseusExerciseGenerator
|
| 47 | +from contentcuration.utils.assessment.qti.archive import QTIExerciseGenerator |
47 | 48 | from contentcuration.utils.cache import delete_public_channel_cache_keys
|
48 | 49 | from contentcuration.utils.files import create_thumbnail_from_base64
|
49 | 50 | from contentcuration.utils.files import get_thumbnail_encoding
|
@@ -320,12 +321,33 @@ def recurse_nodes(self, node, inherited_fields): # noqa C901
|
320 | 321 |
|
321 | 322 | if node.kind_id == content_kinds.EXERCISE:
|
322 | 323 | 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 | + |
323 | 344 | if (
|
324 | 345 | self.force_exercises
|
325 | 346 | 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() |
327 | 348 | ):
|
328 |
| - generator = PerseusExerciseGenerator( |
| 349 | + |
| 350 | + generator = generator_class( |
329 | 351 | node,
|
330 | 352 | exercise_data,
|
331 | 353 | self.channel_id,
|
|
0 commit comments