diff --git a/contentcuration/contentcuration/management/commands/fix_exercise_complete.py b/contentcuration/contentcuration/management/commands/fix_exercise_complete.py index b2e465cb13..74b3438302 100644 --- a/contentcuration/contentcuration/management/commands/fix_exercise_complete.py +++ b/contentcuration/contentcuration/management/commands/fix_exercise_complete.py @@ -20,18 +20,28 @@ class Command(BaseCommand): def handle(self, *args, **options): start = time.time() - reset_time = time.time() - mastery_model_exercise_count = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE)\ + mastery_model_exercise_count = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \ .filter(Q(extra_fields__has_key='mastery_model')).order_by().count() i = 0 while i < mastery_model_exercise_count: chunk_time = time.time() - update_ids = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE)\ - .filter(Q(extra_fields__has_key='mastery_model')).order_by("id").values_list("id", flat=True)[i: i + CHUNKSIZE] + update_ids = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \ + .filter(Q(extra_fields__has_key='mastery_model')).order_by("id").values_list("id", flat=True)[i: i + CHUNKSIZE] + ContentNode.objects.filter(pk__in=update_ids).update(complete=True) + logging.info('Marked {} nodes as complete=True in {} seconds'.format(CHUNKSIZE, time.time() - chunk_time)) + i += CHUNKSIZE + + mastery_model_exercise_count = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \ + .filter(Q(extra_fields__has_key='option.completion_criteria.mastery_model')).order_by().count() + + while i < mastery_model_exercise_count: + chunk_time = time.time() + update_ids = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \ + .filter(Q(extra_fields__has_key='option.completion_criteria.mastery_model')).order_by("id").values_list("id", flat=True)[i: i + CHUNKSIZE] ContentNode.objects.filter(pk__in=update_ids).update(complete=True) logging.info('Marked {} nodes as complete=True in {} seconds'.format(CHUNKSIZE, time.time() - chunk_time)) i += CHUNKSIZE diff --git a/contentcuration/contentcuration/management/commands/mark_incomplete.py b/contentcuration/contentcuration/management/commands/mark_incomplete.py index 95b4702834..0e058b4e95 100644 --- a/contentcuration/contentcuration/management/commands/mark_incomplete.py +++ b/contentcuration/contentcuration/management/commands/mark_incomplete.py @@ -118,6 +118,12 @@ def handle(self, *args, **options): logging.info('Marking mastery_model less exercises...') count = ContentNode.objects.exclude(complete=False).filter(kind_id=content_kinds.EXERCISE).filter(~Q(extra_fields__has_key='mastery_model')) \ .order_by().update(complete=False) + + logging.info('Marked {} mastery_model less exercises(finished in {})'.format(count, time.time() - exercisestart)) + + count = ContentNode.objects.exclude(complete=False).filter(kind_id=content_kinds.EXERCISE).filter(~Q(extra_fields__has_key='mastery_model') & ~Q(extra_fields__has_key='option.completion_criteria.mastery_model')) \ + .order_by().update(complete=False) + logging.info('Marked {} mastery_model less exercises(finished in {})'.format(count, time.time() - exercisestart)) exercisestart = time.time() diff --git a/contentcuration/contentcuration/utils/publish.py b/contentcuration/contentcuration/utils/publish.py index bb200e018d..9e31dd5220 100644 --- a/contentcuration/contentcuration/utils/publish.py +++ b/contentcuration/contentcuration/utils/publish.py @@ -403,7 +403,13 @@ def process_assessment_metadata(ccnode, kolibrinode): randomize = exercise_data.get('randomize') if exercise_data.get('randomize') is not None else True assessment_item_ids = [a.assessment_id for a in assessment_items] - mastery_model = {'type': exercise_data.get('mastery_model') or exercises.M_OF_N} + exercise_data_type = "" + if exercise_data.get('mastery_model'): + exercise_data_type = exercise_data.get('mastery_model') + if exercise_data.get('option') and exercise_data.get('option').get('completion_criteria') and exercise_data.get('option').get('completion_criteria').get('mastery_model'): + exercise_data_type = exercise_data.get('option').get('completion_criteria').get('mastery_model') + + mastery_model = {'type': exercise_data_type or exercises.M_OF_N} if mastery_model['type'] == exercises.M_OF_N: mastery_model.update({'n': exercise_data.get('n') or min(5, assessment_items.count()) or 1}) mastery_model.update({'m': exercise_data.get('m') or min(5, assessment_items.count()) or 1})