Support EXCLUDED blocks in Block Completion Transformer

For now only the discussion blocks were supported. If we had a custom XBlock that specified `completion_mode = XBlockCompletionMode.EXCLUDED`, then it could never be marked as completed on the course outline page, despite being marked as such inside the learning sequence.
This commit is contained in:
Agrendalath
2020-07-30 20:01:56 +02:00
parent 5a27b5df39
commit e571693455
2 changed files with 15 additions and 5 deletions

View File

@@ -45,6 +45,17 @@ class BlockCompletionTransformer(BlockStructureTransformer):
def collect(cls, block_structure):
block_structure.request_xblock_fields('completion_mode')
@staticmethod
def _is_block_excluded(block_structure, block_key):
"""
Checks whether block's completion method is of `EXCLUDED` type.
"""
completion_mode = block_structure.get_xblock_field(
block_key, 'completion_mode'
)
return completion_mode == CompletionMode.EXCLUDED
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
@@ -58,14 +69,13 @@ class BlockCompletionTransformer(BlockStructureTransformer):
"""
if block_key in complete_course_blocks:
block_structure.override_xblock_field(block_key, self.COMPLETE, True)
if block_key == latest_complete_block_key:
if str(block_key) == str(latest_complete_block_key):
block_structure.override_xblock_field(block_key, self.RESUME_BLOCK, True)
children = block_structure.get_children(block_key)
non_discussion_children = (child_key for child_key in children
if block_structure.get_xblock_field(child_key, 'category') != 'discussion')
all_children_complete = all(block_structure.get_xblock_field(child_key, self.COMPLETE)
for child_key in non_discussion_children)
for child_key in children
if not self._is_block_excluded(block_structure, child_key))
if children and all_children_complete:
block_structure.override_xblock_field(block_key, self.COMPLETE, True)

View File

@@ -208,7 +208,7 @@ class TestCourseHomePage(CourseHomePageTestCase): # lint-amnesty, pylint: disab
# Fetch the view and verify the query counts
# TODO: decrease query count as part of REVO-28
with self.assertNumQueries(78, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST):
with self.assertNumQueries(79, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST):
with check_mongo_calls(4):
url = course_home_url(self.course)
self.client.get(url)