refactor: rename module -> block within lms/djangoapps/courseware

Also, removed unused `_has_access_xmodule` methid from `lms/djangoapps/courseware/access.py`.
This commit is contained in:
0x29a
2022-12-23 15:27:31 +01:00
committed by Agrendalath
parent 611563600c
commit 9d8375ff99
55 changed files with 432 additions and 443 deletions

View File

@@ -399,7 +399,7 @@ class ProblemBlock(
def handle_ajax(self, dispatch, data):
"""
This is called by courseware.module_render, to handle an AJAX call.
This is called by courseware.block_render, to handle an AJAX call.
`data` is request.POST.
@@ -1286,7 +1286,7 @@ class ProblemBlock(
id=self.location.html_id(), ajax_url=self.ajax_url, html=HTML(html)
)
# Now do all the substitutions which the LMS module_render normally does, but
# Now do all the substitutions which the LMS block_render normally does, but
# we need to do here explicitly since we can get called for our HTML via AJAX
html = self.runtime.service(self, "replace_urls").replace_urls(html)

View File

@@ -317,7 +317,9 @@ class ConditionalBlock(
"""
Returns a list of bound XBlocks instances upon which XBlock depends.
"""
return [self.system.get_module(descriptor) for descriptor in self.get_required_module_descriptors()]
return [
self.system.get_block_for_descriptor(descriptor) for descriptor in self.get_required_module_descriptors()
]
def get_required_module_descriptors(self):
"""

View File

@@ -30,7 +30,7 @@ log = logging.getLogger(__name__)
# way to tell if the module is being used in a staff context or not. Errors that get discovered
# at course load time are turned into ErrorBlock objects, and automatically hidden from students.
# Unfortunately, we can also have errors when loading modules mid-request, and then we need to decide
# what to show, and the logic for that belongs in the LMS (e.g. in get_module), so the error handler
# what to show, and the logic for that belongs in the LMS (e.g. in get_block), so the error handler
# decides whether to create a staff or not-staff module.

View File

@@ -744,7 +744,7 @@ oauth_consumer_key="", oauth_signature="frVp4JuvT1mVXlxktiAUjQ7%2F1cw%3D"'}
@XBlock.handler
def grade_handler(self, request, suffix): # lint-amnesty, pylint: disable=unused-argument
"""
This is called by courseware.module_render, to handle an AJAX call.
This is called by courseware.block_render, to handle an AJAX call.
Used only for grading. Returns XML response.

View File

@@ -147,7 +147,7 @@ class RebindUserService(Service):
"""
An XBlock Service that allows modules to get rebound to real users if it was previously bound to an AnonymousUser.
This used to be a local function inside the `lms.djangoapps.courseware.module_render.get_module_system_for_user`
This used to be a local function inside the `lms.djangoapps.courseware.block_render.get_module_system_for_user`
method, and was passed as a constructor argument to x_module.ModuleSystem. This has been refactored out into a
service to simplify the ModuleSystem and lives in this module temporarily.
@@ -160,7 +160,7 @@ class RebindUserService(Service):
course (Course) - Course Object
get_module_system_for_user (function) - The helper function that will be called to create a module system
for a specfic user. This is the parent function from which this service was reactored out.
`lms.djangoapps.courseware.module_render.get_module_system_for_user`
`lms.djangoapps.courseware.block_render.get_module_system_for_user`
kwargs (dict) - all the keyword arguments that need to be passed to the `get_module_system_for_user`
function when it is called during rebinding
"""

View File

@@ -192,7 +192,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
Return the user bound child block for the partition or None.
"""
if self.child_descriptor is not None:
return self.system.get_module(self.child_descriptor)
return self.system.get_block_for_descriptor(self.child_descriptor)
else:
return None
@@ -272,7 +272,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
for child_location in self.children: # pylint: disable=no-member
child_descriptor = self.get_child_descriptor_by_location(child_location)
child = self.system.get_module(child_descriptor)
child = self.system.get_block_for_descriptor(child_descriptor)
rendered_child = child.render(STUDENT_VIEW, context)
fragment.add_fragment_resources(rendered_child)
group_name, updated_group_id = self.get_data_for_vertical(child)
@@ -347,7 +347,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
"""
html = ""
for active_child_descriptor in children:
active_child = self.system.get_module(active_child_descriptor)
active_child = self.system.get_block_for_descriptor(active_child_descriptor)
rendered_child = active_child.render(StudioEditableBlock.get_preview_view_name(active_child), context)
if active_child.category == 'vertical':
group_name, group_id = self.get_data_for_vertical(active_child)

View File

@@ -121,8 +121,8 @@ def get_test_system(
id_manager = CourseLocationManager(course_id)
def get_module(descriptor):
"""Mocks module_system get_module function"""
def get_block(descriptor):
"""Mocks module_system get_block function"""
# Unlike XBlock Runtimes or DescriptorSystems,
# each XModule is provided with a new ModuleSystem.
@@ -138,7 +138,7 @@ def get_test_system(
return descriptor
return TestModuleSystem(
get_module=get_module,
get_block=get_block,
services={
'user': user_service,
'mako': mako_service,

View File

@@ -130,9 +130,9 @@ class ConditionalFactory:
ScopeIds(None, None, cond_location, cond_location)
)
cond_descriptor.xmodule_runtime = system
system.get_module = lambda desc: desc if visible_to_nonstaff_users(desc) else None
system.get_block_for_descriptor = lambda desc: desc if visible_to_nonstaff_users(desc) else None
cond_descriptor.get_required_blocks = [
system.get_module(source_descriptor),
system.get_block_for_descriptor(source_descriptor),
]
# return dict:
@@ -228,7 +228,7 @@ class ConditionalBlockXmlTest(unittest.TestCase):
def get_module_for_location(self, location):
descriptor = self.modulestore.get_item(location, depth=None)
return self.test_system.get_module(descriptor)
return self.test_system.get_block_for_descriptor(descriptor)
@patch('xmodule.x_module.descriptor_global_local_resource_url')
@patch.dict(settings.FEATURES, {'ENABLE_EDXNOTES': False})

View File

@@ -62,15 +62,15 @@ class LibraryContentTest(MixedSplitTestCase):
module_system.descriptor_runtime = module.runtime._descriptor_system # pylint: disable=protected-access
module_system._services['library_tools'] = self.tools # pylint: disable=protected-access
def get_module(descriptor):
"""Mocks module_system get_module function"""
def get_block(descriptor):
"""Mocks module_system get_block function"""
sub_module_system = get_test_system(course_id=module.location.course_key)
sub_module_system.get_module = get_module
sub_module_system.get_block_for_descriptor = get_block
sub_module_system.descriptor_runtime = descriptor._runtime # pylint: disable=protected-access
descriptor.bind_for_student(sub_module_system, self.user_id)
return descriptor
module_system.get_module = get_module
module_system.get_block_for_descriptor = get_block
module.xmodule_runtime = module_system

View File

@@ -480,7 +480,7 @@ class VideoStudioViewHandlers:
We raise all exceptions right in Studio:
NotFoundError:
Video or asset was deleted from module/contentstore, but request came later.
Seems impossible to be raised. module_render.py catches NotFoundErrors from here.
Seems impossible to be raised. block_render.py catches NotFoundErrors from here.
/translation POST:
TypeError:

View File

@@ -1656,15 +1656,15 @@ class ModuleSystem(MetricsMixin, ConfigurableFragmentWrapper, ModuleSystemShim,
def __init__(
self,
get_module,
get_block,
descriptor_runtime,
**kwargs,
**kwargs
):
"""
Create a closure around the system environment.
get_module - function that takes a descriptor and returns a corresponding
module instance object. If the current user does not have
get_block - function that takes a descriptor and returns a corresponding
block instance object. If the current user does not have
access to that location, returns None.
descriptor_runtime - A `DescriptorSystem` to use for loading xblocks by id
@@ -1674,7 +1674,7 @@ class ModuleSystem(MetricsMixin, ConfigurableFragmentWrapper, ModuleSystemShim,
kwargs.setdefault('id_generator', getattr(descriptor_runtime, 'id_generator', AsideKeyGenerator()))
super().__init__(**kwargs)
self.get_module = get_module
self.get_block_for_descriptor = get_block
self.xmodule_instance = None
@@ -1705,7 +1705,7 @@ class ModuleSystem(MetricsMixin, ConfigurableFragmentWrapper, ModuleSystemShim,
return self.handler_url(self.xmodule_instance, 'xmodule_handler', '', '').rstrip('/?')
def get_block(self, block_id, for_parent=None): # lint-amnesty, pylint: disable=arguments-differ
return self.get_module(self.descriptor_runtime.get_block(block_id, for_parent=for_parent))
return self.get_block_for_descriptor(self.descriptor_runtime.get_block(block_id, for_parent=for_parent))
def resource_url(self, resource):
raise NotImplementedError("edX Platform doesn't currently implement XBlock resource urls")