refactor: rename descriptor -> block within remaining xmodule

Co-authored-by: Agrendalath <piotr@surowiec.it>
This commit is contained in:
Pooja Kulkarni
2023-01-05 14:30:42 -05:00
committed by Agrendalath
parent ce94d896cf
commit 1950949c9e
15 changed files with 83 additions and 83 deletions

View File

@@ -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

View File

@@ -22,5 +22,5 @@ class LMSXBlockConfig(AppConfig):
# 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

View File

@@ -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

View File

@@ -213,8 +213,8 @@ class ConditionalBlock(
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
@@ -244,7 +244,7 @@ class ConditionalBlock(
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,
@@ -298,7 +298,7 @@ class ConditionalBlock(
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:
@@ -318,24 +318,24 @@ class ConditionalBlock(
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):
@@ -357,8 +357,8 @@ class ConditionalBlock(
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)

View File

@@ -97,8 +97,8 @@ class ErrorBlock(
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()
@@ -141,19 +141,19 @@ class ErrorBlock(
)
@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.

View File

@@ -468,7 +468,7 @@ class LibraryContentBlock(
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.
"""
@@ -701,7 +701,7 @@ class LibraryContentBlock(
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
@@ -714,7 +714,7 @@ class LibraryContentBlock(
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

View File

@@ -125,9 +125,9 @@ class LibraryToolsService:
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):
"""

View File

@@ -85,7 +85,7 @@ class RandomizeBlock(
return child
def get_child_descriptors(self):
def get_child_blocks(self):
"""
For grading--return just the chosen child.
"""
@@ -99,7 +99,7 @@ class RandomizeBlock(
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)
@@ -120,6 +120,6 @@ class RandomizeBlock(
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

View File

@@ -190,7 +190,7 @@ class RebindUserService(Service):
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,

View File

@@ -177,13 +177,13 @@ 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
@@ -191,15 +191,15 @@ 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.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():
@@ -227,7 +227,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
"""
return self.child.get_content_titles()
def get_child_descriptors(self):
def get_child_blocks(self):
"""
For grading--return just the chosen child.
"""
@@ -239,19 +239,19 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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):
"""
@@ -271,8 +271,8 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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)
@@ -346,8 +346,8 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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)
@@ -378,7 +378,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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:
@@ -464,8 +464,8 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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)
@@ -486,7 +486,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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
@@ -561,9 +561,9 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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:
@@ -575,7 +575,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
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)

View File

@@ -51,8 +51,8 @@ class StudioEditableBlock(XBlockMixin):
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)

View File

@@ -21,13 +21,13 @@ log = logging.getLogger(__name__)
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

View File

@@ -241,13 +241,13 @@ def get_transcripts_from_youtube(youtube_id, settings, i18n, youtube_transcript_
return {'start': sub_starts, 'end': sub_ends, 'text': sub_texts}
def download_youtube_subs(youtube_id, video_descriptor, settings): # lint-amnesty, pylint: disable=redefined-outer-name
def download_youtube_subs(youtube_id, video_block, settings): # lint-amnesty, pylint: disable=redefined-outer-name
"""
Download transcripts from Youtube.
Args:
youtube_id: str, actual youtube_id of the video.
video_descriptor: video descriptor instance.
video_block: video block instance.
We save transcripts for 1.0 speed, as for other speed conversion is done on front-end.
@@ -257,7 +257,7 @@ def download_youtube_subs(youtube_id, video_descriptor, settings): # lint-amnes
Raises:
GetTranscriptsFromYouTubeException, if fails.
"""
i18n = video_descriptor.runtime.service(video_descriptor, "i18n")
i18n = video_block.runtime.service(video_block, "i18n")
_ = i18n.ugettext
subs = get_transcripts_from_youtube(youtube_id, settings, i18n)
@@ -961,7 +961,7 @@ def get_transcript_from_contentstore(video, language, output_format, transcripts
Get video transcript from content store.
Arguments:
video (Video Descriptor): Video descriptor
video (Video block): Video block
language (unicode): transcript language
output_format (unicode): transcript output format
transcripts_info (dict): transcript info for a video
@@ -1089,7 +1089,7 @@ def get_transcript(video, lang=None, output_format=Transcript.SRT, youtube_id=No
Get video transcript from edx-val or content store.
Arguments:
video (Video Descriptor): Video Descriptor
video (Video block): Video block
lang (unicode): transcript language
output_format (unicode): transcript output format
youtube_id (unicode): youtube video id

View File

@@ -286,7 +286,7 @@ class XModuleMixin(XModuleFields, XBlock):
Adding this Mixin to an :class:`XBlock` allows it to cooperate with old-style :class:`XModules`
"""
# Attributes for inspection of the descriptor
# Attributes for inspection of the block
# This indicates whether the xmodule is a problem-type.
# It should respond to max_score() and grade(). It can be graded or ungraded
@@ -299,7 +299,7 @@ class XModuleMixin(XModuleFields, XBlock):
# Class level variable
# True if this descriptor always requires recalculation of grades, for
# True if this block always requires recalculation of grades, for
# example if the score can change via an extrnal service, not just when the
# student interacts with the module on the page. A specific example is
# FoldIt, which posts grade-changing updates through a separate API.
@@ -563,10 +563,10 @@ class XModuleMixin(XModuleFields, XBlock):
def has_dynamic_children(self):
"""
Returns True if this descriptor has dynamic children for a given
Returns True if this block has dynamic children for a given
student when the module is created.
Returns False if the children of this descriptor are the same
Returns False if the children of this block are the same
children that the module will return for any student.
"""
return False
@@ -1002,7 +1002,7 @@ class ConfigurableFragmentWrapper:
# Runtime.handler_url interface.
#
# The monkey-patching happens in cms/djangoapps/xblock_config/apps.py and lms/djangoapps/lms_xblock/apps.py
def descriptor_global_handler_url(block, handler_name, suffix='', query='', thirdparty=False):
def block_global_handler_url(block, handler_name, suffix='', query='', thirdparty=False):
"""
See :meth:`xblock.runtime.Runtime.handler_url`.
"""
@@ -1014,7 +1014,7 @@ def descriptor_global_handler_url(block, handler_name, suffix='', query='', thir
# the Runtime part of its interface. This function matches the Runtime.local_resource_url interface
#
# The monkey-patching happens in cms/djangoapps/xblock_config/apps.py and lms/djangoapps/lms_xblock/apps.py
def descriptor_global_local_resource_url(block, uri):
def block_global_local_resource_url(block, uri):
"""
See :meth:`xblock.runtime.Runtime.local_resource_url`.
"""
@@ -1529,7 +1529,7 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, ModuleSystemSh
# defined for LMS/CMS through the handler_url_override property.
if getattr(self, 'handler_url_override', None):
return self.handler_url_override(block, handler_name, suffix, query, thirdparty)
return descriptor_global_handler_url(block, handler_name, suffix, query, thirdparty)
return block_global_handler_url(block, handler_name, suffix, query, thirdparty)
def local_resource_url(self, block, uri):
"""
@@ -1539,7 +1539,7 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, ModuleSystemSh
# This means that LMS/CMS don't have a way to define a subclass of DescriptorSystem
# that implements the correct local_resource_url. So, for now, instead, we will reference a
# global function that the application can override.
return descriptor_global_local_resource_url(block, uri)
return block_global_local_resource_url(block, uri)
def applicable_aside_types(self, block):
"""

View File

@@ -152,7 +152,7 @@ class XmlMixin:
@classmethod
def definition_from_xml(cls, xml_object, system):
"""
Return the definition to be passed to the newly created descriptor
Return the definition to be passed to the newly created block
during from_xml
xml_object: An etree Element
@@ -199,7 +199,7 @@ class XmlMixin:
@classmethod
def load_definition(cls, xml_object, system, def_id, id_generator):
"""
Load a descriptor definition from the specified xml_object.
Load a block from the specified xml_object.
Subclasses should not need to override this except in special
cases (e.g. html block)
@@ -365,7 +365,7 @@ class XmlMixin:
xblock = runtime.construct_xblock_from_class(
cls,
# We're loading a descriptor, so student_id is meaningless
# We're loading a block, so student_id is meaningless
ScopeIds(None, node.tag, def_id, usage_id),
field_data,
)
@@ -405,7 +405,7 @@ class XmlMixin:
return f'{category}/{name}.{cls.filename_extension}'
def export_to_file(self):
"""If this returns True, write the definition of this descriptor to a separate
"""If this returns True, write the definition of this block to a separate
file.
NOTE: Do not override this without a good reason. It is here