refactor: rename module (or item) -> block within common

This commit is contained in:
0x29a
2023-01-02 15:26:17 +01:00
committed by Agrendalath
parent d338f00e39
commit e96155807a
4 changed files with 40 additions and 40 deletions

View File

@@ -23,7 +23,7 @@ from cms.djangoapps.contentstore.courseware_index import (
LibrarySearchIndexer,
)
from common.djangoapps.track.event_transaction_utils import get_event_transaction_id, get_event_transaction_type
from common.djangoapps.util.module_utils import yield_dynamic_descriptor_descendants
from common.djangoapps.util.block_utils import yield_dynamic_descriptor_descendants
from lms.djangoapps.grades.api import task_compute_all_grades_for_course
from openedx.core.djangoapps.content.learning_sequences.api import key_supports_outlines
from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course_task

View File

@@ -0,0 +1,36 @@
"""
Utility library containing operations used/shared by multiple CourseBlocks.
"""
def yield_dynamic_descriptor_descendants(descriptor, user_id, block_creator=None):
"""
This returns all of the descendants of a descriptor. If the descriptor
has dynamic children, the block will be created using block_creator
and the children (as descriptors) of that module will be returned.
"""
stack = [descriptor]
while len(stack) > 0:
next_descriptor = stack.pop()
stack.extend(get_dynamic_descriptor_children(next_descriptor, user_id, block_creator))
yield next_descriptor
def get_dynamic_descriptor_children(descriptor, user_id, block_creator=None, usage_key_filter=None):
"""
Returns the children of the given descriptor, while supporting descriptors with dynamic children.
"""
block_children = []
if descriptor.has_dynamic_children():
block = None
if descriptor.scope_ids.user_id and user_id == descriptor.scope_ids.user_id:
# do not rebind the block if it's already bound to a user.
block = descriptor
elif block_creator:
block = block_creator(descriptor)
if block:
block_children = block.get_child_descriptors()
else:
block_children = descriptor.get_children(usage_key_filter)
return block_children

View File

@@ -1,36 +0,0 @@
"""
Utility library containing operations used/shared by multiple courseware modules
"""
def yield_dynamic_descriptor_descendants(descriptor, user_id, module_creator=None):
"""
This returns all of the descendants of a descriptor. If the descriptor
has dynamic children, the module will be created using module_creator
and the children (as descriptors) of that module will be returned.
"""
stack = [descriptor]
while len(stack) > 0:
next_descriptor = stack.pop()
stack.extend(get_dynamic_descriptor_children(next_descriptor, user_id, module_creator))
yield next_descriptor
def get_dynamic_descriptor_children(descriptor, user_id, module_creator=None, usage_key_filter=None):
"""
Returns the children of the given descriptor, while supporting descriptors with dynamic children.
"""
module_children = []
if descriptor.has_dynamic_children():
module = None
if descriptor.scope_ids.user_id and user_id == descriptor.scope_ids.user_id:
# do not rebind the module if it's already bound to a user.
module = descriptor
elif module_creator:
module = module_creator(descriptor)
if module:
module_children = module.get_child_descriptors()
else:
module_children = descriptor.get_children(usage_key_filter)
return module_children

View File

@@ -926,7 +926,7 @@ class TestHandleXBlockCallback(SharedModuleStoreTestCase, LoginEnrollmentTestCas
)
@ddt.unpack
@patch('lms.djangoapps.courseware.block_render.get_block_for_descriptor', wraps=get_block_for_descriptor)
def test_will_recheck_access_handler_attribute(self, handler, will_recheck_access, mock_get_module):
def test_will_recheck_access_handler_attribute(self, handler, will_recheck_access, mock_get_block):
"""Confirm that we pay attention to any 'will_recheck_access' attributes on handler methods"""
course = CourseFactory.create()
descriptor_kwargs = {
@@ -941,8 +941,8 @@ class TestHandleXBlockCallback(SharedModuleStoreTestCase, LoginEnrollmentTestCas
request.user = self.mock_user
render.handle_xblock_callback(request, str(course.id), usage_id, handler)
assert mock_get_module.call_count == 1
assert mock_get_module.call_args[1]['will_recheck_access'] == will_recheck_access
assert mock_get_block.call_count == 1
assert mock_get_block.call_args[1]['will_recheck_access'] == will_recheck_access
@ddt.ddt