diff --git a/lms/djangoapps/course_api/blocks/transformers/block_completion.py b/lms/djangoapps/course_api/blocks/transformers/block_completion.py index dad229953e..3810825114 100644 --- a/lms/djangoapps/course_api/blocks/transformers/block_completion.py +++ b/lms/djangoapps/course_api/blocks/transformers/block_completion.py @@ -45,20 +45,20 @@ class BlockCompletionTransformer(BlockStructureTransformer): def collect(cls, block_structure): block_structure.request_xblock_fields('completion_mode') - def mark_complete(self, course_block_completions, latest_completion_block_key, block_key, block_structure): + def mark_complete(self, complete_course_blocks, latest_complete_block_key, block_key, block_structure): """ Helper function to mark a block as 'complete' as dictated by - course_block_completions (for problems) or all of a block's children being complete. + complete_course_blocks (for problems) or all of a block's children being complete. This also sets the 'resume_block' field as that is connected to the latest completed block. - :param course_block_completions: dict[course_completion_object] = completion_value - :param latest_completion_block_key: block key for the latest completed block. + :param complete_course_blocks: container of complete block keys + :param latest_complete_block_key: block key for the latest completed block. :param block_key: A opaque_keys.edx.locator.BlockUsageLocator object :param block_structure: A BlockStructureBlockData object """ - if block_key in course_block_completions: + if block_key in complete_course_blocks: block_structure.override_xblock_field(block_key, self.COMPLETE, True) - if block_key == latest_completion_block_key: + if block_key == latest_complete_block_key: block_structure.override_xblock_field(block_key, self.RESUME_BLOCK, True) children = block_structure.get_children(block_key) @@ -81,10 +81,10 @@ class BlockCompletionTransformer(BlockStructureTransformer): IMPORTANT!: There is a subtle, but important difference between 'completion' and 'complete' which are both set in this transformer: - 'completion': Returns a percentile (0.0 - 1.0) of correctness for a _problem_. This field will + 'completion': Returns a percentile (0.0 - 1.0) of completion for a _problem_. This field will be None for all other blocks that are not leaves and captured in BlockCompletion. 'complete': Returns a boolean indicating whether the block is complete. For problems, this will - be taken from a BlockCompletion entry existing. For all other blocks, it will be marked True + be taken from a BlockCompletion 1.0 entry existing. For all other blocks, it will be marked True if all of the children of the block are all marked complete (this is calculated recursively) """ def _is_block_an_aggregator_or_excluded(block_key): @@ -123,8 +123,9 @@ class BlockCompletionTransformer(BlockStructureTransformer): block_key, self, self.COMPLETION, completion_value ) - latest_completion = completions.latest() if completions.exists() else None - if latest_completion: - latest_completion_block_key = latest_completion[0] + complete_blocks = completions.filter(completion=1.0) + latest_complete_key = complete_blocks.latest()[0] if complete_blocks else None + if latest_complete_key: + complete_keys = {key for key, completion in completions_dict.items() if completion == 1.0} for block_key in block_structure.post_order_traversal(): - self.mark_complete(completions_dict, latest_completion_block_key, block_key, block_structure) + self.mark_complete(complete_keys, latest_complete_key, block_key, block_structure)