Skip to content

Commit

Permalink
refactor: rename descriptor -> block within remaining xmodule
Browse files Browse the repository at this point in the history
Co-authored-by: Agrendalath <[email protected]>
  • Loading branch information
pkulkark and Agrendalath committed Apr 26, 2023
1 parent ce94d89 commit 1950949
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 83 deletions.
6 changes: 3 additions & 3 deletions cms/djangoapps/xblock_config/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class XBlockConfig(AppConfig):
def ready(self):
from openedx.core.lib.xblock_utils import xblock_local_resource_url

# In order to allow descriptors to use a handler url, we need to
# In order to allow blocks to use a handler url, we need to
# monkey-patch the x_module library.
# TODO: Remove this code when Runtimes are no longer created by modulestores
# https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes
xmodule.x_module.descriptor_global_handler_url = cms.lib.xblock.runtime.handler_url
xmodule.x_module.descriptor_global_local_resource_url = xblock_local_resource_url
xmodule.x_module.block_global_handler_url = cms.lib.xblock.runtime.handler_url
xmodule.x_module.block_global_local_resource_url = xblock_local_resource_url
4 changes: 2 additions & 2 deletions lms/djangoapps/lms_xblock/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def ready(self):
# monkey-patch the x_module library.
# TODO: Remove this code when Runtimes are no longer created by modulestores
# https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes
xmodule.x_module.descriptor_global_handler_url = handler_url
xmodule.x_module.descriptor_global_local_resource_url = local_resource_url
xmodule.x_module.block_global_handler_url = handler_url
xmodule.x_module.block_global_local_resource_url = local_resource_url
2 changes: 1 addition & 1 deletion xmodule/block_metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def display_name_with_default(block):
a name based on the URL.
Unlike the rest of this module's functions, this function takes an entire
course descriptor/overview as a parameter. This is because a few test cases
course block/overview as a parameter. This is because a few test cases
(specifically, {Text|Image|Video}AnnotationModuleTestCase.test_student_view)
create scenarios where course.display_name is not None but course.location
is None, which causes calling course.url_name to fail. So, although we'd
Expand Down
22 changes: 11 additions & 11 deletions xmodule/conditional_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def is_condition_satisfied(self): # lint-amnesty, pylint: disable=missing-funct
for block in self.get_required_blocks:
if not hasattr(block, attr_name):
# We don't throw an exception here because it is possible for
# the descriptor of a required block to have a property but
# for the resulting module to be a (flavor of) ErrorBlock.
# the required block to have a property but
# for the resulting block to be a (flavor of) ErrorBlock.
# So just log and return false.
if block is not None:
# We do not want to log when block is None, and it is when requester
Expand Down Expand Up @@ -244,7 +244,7 @@ def student_view(self, _context):
return fragment

def get_html(self):
required_html_ids = [descriptor.location.html_id() for descriptor in self.get_required_blocks]
required_html_ids = [block.location.html_id() for block in self.get_required_blocks]
return self.runtime.service(self, 'mako').render_template('conditional_ajax.html', {
'element_id': self.location.html_id(),
'ajax_url': self.ajax_url,
Expand Down Expand Up @@ -298,7 +298,7 @@ def get_icon_class(self):
class_priority = ['video', 'problem']

child_classes = [
child_descriptor.get_icon_class() for child_descriptor in self.get_children()
child_block.get_icon_class() for child_block in self.get_children()
]
for c in class_priority:
if c in child_classes:
Expand All @@ -318,24 +318,24 @@ def get_required_blocks(self):
Returns a list of bound XBlocks instances upon which XBlock depends.
"""
return [
self.runtime.get_block_for_descriptor(descriptor) for descriptor in self.get_required_block_descriptors()
self.runtime.get_block_for_descriptor(block) for block in self.get_required_block_descriptors()
]

def get_required_block_descriptors(self):
"""
Returns a list of unbound XBlocks instances upon which this XBlock depends.
"""
descriptors = []
blocks = []
for location in self.sources_list:
try:
descriptor = self.runtime.get_block(location)
descriptors.append(descriptor)
block = self.runtime.get_block(location)
blocks.append(block)
except ItemNotFoundError:
msg = "Invalid module by location."
log.exception(msg)
self.runtime.error_tracker(msg)

return descriptors
return blocks

@classmethod
def definition_from_xml(cls, xml_object, system):
Expand All @@ -357,8 +357,8 @@ def definition_from_xml(cls, xml_object, system):
show_tag_list.append(location)
else:
try:
descriptor = system.process_xml(etree.tostring(child, encoding='unicode'))
children.append(descriptor.scope_ids.usage_id)
block = system.process_xml(etree.tostring(child, encoding='unicode'))
children.append(block.scope_ids.usage_id)
except: # lint-amnesty, pylint: disable=bare-except
msg = "Unable to load child when parsing Conditional."
log.exception(msg)
Expand Down
16 changes: 8 additions & 8 deletions xmodule/error_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def _construct(cls, system, contents, error_msg, location, for_parent=None):
if location.block_type == 'error':
location = location.replace(
# Pick a unique url_name -- the sha1 hash of the contents.
# NOTE: We could try to pull out the url_name of the errored descriptor,
# but url_names aren't guaranteed to be unique between descriptor types,
# NOTE: We could try to pull out the url_name of the errored block,
# but url_names aren't guaranteed to be unique between block types,
# and ErrorBlock can wrap any type. When the wrapped block is fixed,
# it will be written out with the original url_name.
name=hashlib.sha1(contents.encode('utf8')).hexdigest()
Expand Down Expand Up @@ -141,19 +141,19 @@ def from_json(cls, json_data, system, location, error_msg='Error not available')
)

@classmethod
def from_descriptor(cls, descriptor, error_msg=None):
def from_block(cls, block, error_msg=None):
return cls._construct(
descriptor.runtime,
str(descriptor),
block.runtime,
str(block),
error_msg,
location=descriptor.location,
for_parent=descriptor.get_parent() if descriptor.has_cached_parent else None
location=block.location,
for_parent=block.get_parent() if block.has_cached_parent else None
)

@classmethod
def from_xml(cls, xml_data, system, id_generator, # pylint: disable=arguments-differ
error_msg=None):
'''Create an instance of this descriptor from the supplied data.
'''Create an instance of this block from the supplied data.
Does not require that xml_data be parseable--just stores it and exports
as-is if not.
Expand Down
6 changes: 3 additions & 3 deletions xmodule/library_content_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def studio_view(self, _context):
shim_xmodule_js(fragment, self.studio_js_module_name)
return fragment

def get_child_descriptors(self):
def get_child_blocks(self):
"""
Return only the subset of our children relevant to the current student.
"""
Expand Down Expand Up @@ -701,7 +701,7 @@ def editor_saved(self, user, old_metadata, old_content): # lint-amnesty, pylint
def has_dynamic_children(self):
"""
Inform the runtime that our children vary per-user.
See get_child_descriptors() above
See get_child_blocks() above
"""
return True

Expand All @@ -714,7 +714,7 @@ def get_content_titles(self):
This overwrites the get_content_titles method included in x_module by default.
"""
titles = []
for child in self.get_child_descriptors():
for child in self.get_child_blocks():
titles.extend(child.get_content_titles())
return titles

Expand Down
6 changes: 3 additions & 3 deletions xmodule/library_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def _filter_child(self, usage_key, capa_type):
if usage_key.block_type != "problem":
return False

descriptor = self.store.get_item(usage_key, depth=0)
assert isinstance(descriptor, ProblemBlock)
return capa_type in descriptor.problem_types
block = self.store.get_item(usage_key, depth=0)
assert isinstance(block, ProblemBlock)
return capa_type in block.problem_types

def can_use_library_content(self, block):
"""
Expand Down
6 changes: 3 additions & 3 deletions xmodule/randomize_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def child(self):

return child

def get_child_descriptors(self):
def get_child_blocks(self):
"""
For grading--return just the chosen child.
"""
Expand All @@ -99,7 +99,7 @@ def student_view(self, context):
The student view.
"""
if self.child is None:
# raise error instead? In fact, could complain on descriptor load...
# raise error instead? In fact, could complain on block load...
return Fragment(content="<div>Nothing to randomize between</div>")

return self.child.render(STUDENT_VIEW, context)
Expand All @@ -120,6 +120,6 @@ def definition_to_xml(self, resource_fs):
def has_dynamic_children(self):
"""
Grading needs to know that only one of the children is actually "real". This
makes it use block.get_child_descriptors().
makes it use block.get_child_blocks().
"""
return True
2 changes: 1 addition & 1 deletion xmodule/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def rebind_noauth_module_to_user(self, block, real_user):
log.error(err_msg)
raise RebindUserServiceError(err_msg)

field_data_cache_real_user = FieldDataCache.cache_for_descriptor_descendents(
field_data_cache_real_user = FieldDataCache.cache_for_block_descendents(
self.course_id,
real_user,
block,
Expand Down
48 changes: 24 additions & 24 deletions xmodule/split_test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,29 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
}

@cached_property
def child_descriptor(self):
def child_block(self):
"""
Return the child block for the partition or None.
"""
child_descriptors = self.get_child_descriptors()
if len(child_descriptors) >= 1:
return child_descriptors[0]
child_blocks = self.get_child_blocks()
if len(child_blocks) >= 1:
return child_blocks[0]
return None

@cached_property
def child(self):
"""
Return the user bound child block for the partition or None.
"""
if self.child_descriptor is not None:
return self.runtime.get_block_for_descriptor(self.child_descriptor)
if self.child_block is not None:
return self.runtime.get_block_for_descriptor(self.child_block)
else:
return None

def get_child_descriptor_by_location(self, location):
def get_child_block_by_location(self, location):
"""
Look through the children and look for one with the given location.
Returns the descriptor.
Returns the block.
If none match, return None
"""
for child in self.get_children():
Expand Down Expand Up @@ -227,7 +227,7 @@ def get_content_titles(self):
"""
return self.child.get_content_titles()

def get_child_descriptors(self):
def get_child_blocks(self):
"""
For grading--return just the chosen child.
"""
Expand All @@ -239,19 +239,19 @@ def get_child_descriptors(self):
str_group_id = str(group_id)
if str_group_id in self.group_id_to_child:
child_location = self.group_id_to_child[str_group_id]
child_descriptor = self.get_child_descriptor_by_location(child_location)
child_block = self.get_child_block_by_location(child_location)
else:
# Oops. Config error.
log.debug("configuration error in split test block: invalid group_id %r (not one of %r). Showing error", str_group_id, list(self.group_id_to_child.keys())) # lint-amnesty, pylint: disable=line-too-long

if child_descriptor is None:
# Peak confusion is great. Now that we set child_descriptor,
if child_block is None:
# Peak confusion is great. Now that we set child_block,
# get_children() should return a list with one element--the
# xmodule for the child
log.debug("configuration error in split test block: no such child")
return []

return [child_descriptor]
return [child_block]

def get_group_id(self):
"""
Expand All @@ -271,8 +271,8 @@ def _staff_view(self, context):
inactive_contents = []

for child_location in self.children: # pylint: disable=no-member
child_descriptor = self.get_child_descriptor_by_location(child_location)
child = self.runtime.get_block_for_descriptor(child_descriptor)
child_block = self.get_child_block_by_location(child_location)
child = self.runtime.get_block_for_descriptor(child_block)
rendered_child = child.render(STUDENT_VIEW, context)
fragment.add_fragment_resources(rendered_child)
group_name, updated_group_id = self.get_data_for_vertical(child)
Expand Down Expand Up @@ -346,8 +346,8 @@ def studio_render_children(self, fragment, children, context):
dependencies are added to the specified fragment.
"""
html = ""
for active_child_descriptor in children:
active_child = self.runtime.get_block_for_descriptor(active_child_descriptor)
for active_child_block in children:
active_child = self.runtime.get_block_for_descriptor(active_child_block)
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)
Expand Down Expand Up @@ -378,7 +378,7 @@ def student_view(self, context):
conditions for staff.
"""
if self.child is None:
# raise error instead? In fact, could complain on descriptor load...
# raise error instead? In fact, could complain on block load...
return Fragment(content="<div>Nothing here. Move along.</div>")

if self.runtime.user_is_staff:
Expand Down Expand Up @@ -464,8 +464,8 @@ def definition_from_xml(cls, xml_object, system):

for child in xml_object:
try:
descriptor = system.process_xml(etree.tostring(child))
children.append(descriptor.scope_ids.usage_id)
block = system.process_xml(etree.tostring(child))
children.append(block.scope_ids.usage_id)
except Exception: # lint-amnesty, pylint: disable=broad-except
msg = "Unable to load child when parsing split_test block."
log.exception(msg)
Expand All @@ -486,7 +486,7 @@ def get_context(self):
def has_dynamic_children(self):
"""
Grading needs to know that only one of the children is actually "real". This
makes it use block.get_child_descriptors().
makes it use block.get_child_blocks().
"""
return True

Expand Down Expand Up @@ -561,9 +561,9 @@ def active_and_inactive_children(self):
if not user_partition:
return [], children

def get_child_descriptor(location):
def get_child_block(location):
"""
Returns the child descriptor which matches the specified location, or None if one is not found.
Returns the child block which matches the specified location, or None if one is not found.
"""
for child in children:
if child.location == location:
Expand All @@ -575,7 +575,7 @@ def get_child_descriptor(location):
for group in user_partition.groups:
group_id = str(group.id)
child_location = self.group_id_to_child.get(group_id, None)
child = get_child_descriptor(child_location)
child = get_child_block(child_location)
if child:
active_children.append(child)

Expand Down
6 changes: 3 additions & 3 deletions xmodule/studio_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def get_preview_view_name(block):
return AUTHOR_VIEW if has_author_view(block) else STUDENT_VIEW


def has_author_view(descriptor):
def has_author_view(block):
"""
Returns True if the xmodule linked to the descriptor supports "author_view".
Returns True if the xmodule linked to the block supports "author_view".
"""
return getattr(descriptor, 'has_author_view', False)
return getattr(block, 'has_author_view', False)
8 changes: 4 additions & 4 deletions xmodule/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

def all_templates():
"""
Returns all templates for enabled modules, grouped by descriptor type
Returns all templates for enabled modules, grouped by block type
"""
# TODO use memcache to memoize w/ expiration
templates = defaultdict(list)
for category, descriptor in XBlock.load_classes():
if not hasattr(descriptor, 'templates'):
for category, block in XBlock.load_classes():
if not hasattr(block, 'templates'):
continue
templates[category] = descriptor.templates()
templates[category] = block.templates()

return templates
Loading

0 comments on commit 1950949

Please sign in to comment.