From ea99bd853b03876095e0631c861bc31e0a597f8a Mon Sep 17 00:00:00 2001 From: farhan Date: Fri, 26 Dec 2025 18:54:42 +0500 Subject: [PATCH 1/2] chore: Remove XModuleMixin legacy attributes from word cloud --- xblocks_contrib/word_cloud/word_cloud.py | 38 ++++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/xblocks_contrib/word_cloud/word_cloud.py b/xblocks_contrib/word_cloud/word_cloud.py index 58f0f63a..26c3cedd 100644 --- a/xblocks_contrib/word_cloud/word_cloud.py +++ b/xblocks_contrib/word_cloud/word_cloud.py @@ -99,25 +99,25 @@ class WordCloudBlock(StudioEditableXBlockMixin, LegacyXmlMixin, XBlock): scope=Scope.user_state_summary ) - @property - def category(self): - return self.scope_ids.block_type - - @property - def url_name(self): - return self.location.block_id - - @property - def location(self): - return self.scope_ids.usage_id - - @location.setter - def location(self, value): - assert isinstance(value, UsageKey) - self.scope_ids = self.scope_ids._replace( - def_id=value, # Note: assigning a UsageKey as def_id is OK in old mongo / import system but wrong in split - usage_id=value, - ) + # @property + # def category(self): + # return self.scope_ids.block_type + + # @property + # def url_name(self): + # return self.location.block_id + + # @property + # def location(self): + # return self.scope_ids.usage_id + + # @location.setter + # def location(self, value): + # assert isinstance(value, UsageKey) + # self.scope_ids = self.scope_ids._replace( + # def_id=value, # Note: assigning a UsageKey as def_id is OK in old mongo / import system but wrong in split + # usage_id=value, + # ) @staticmethod def workbench_scenarios(): From 22b71fcbbcea40346f54ea31b63c3f0de41c867c Mon Sep 17 00:00:00 2001 From: farhan Date: Mon, 5 Jan 2026 14:00:24 +0500 Subject: [PATCH 2/2] chore: replace XModuleMixin properties with block fields --- xblocks_contrib/annotatable/annotatable.py | 10 +++++----- xblocks_contrib/common/xml_utils.py | 20 ++++++++++---------- xblocks_contrib/html/html.py | 8 ++++---- xblocks_contrib/lti/lti.py | 14 +++++++------- xblocks_contrib/poll/poll.py | 6 +++--- xblocks_contrib/word_cloud/word_cloud.py | 2 +- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/xblocks_contrib/annotatable/annotatable.py b/xblocks_contrib/annotatable/annotatable.py index 0c2c8755..dce8333b 100644 --- a/xblocks_contrib/annotatable/annotatable.py +++ b/xblocks_contrib/annotatable/annotatable.py @@ -31,7 +31,7 @@ class SerializationError(Exception): """ def __init__(self, location, msg): super().__init__(msg) - self.location = location + self.scope_ids.usage_id = location @XBlock.needs("i18n") @@ -279,8 +279,8 @@ def definition_to_xml(self, resource_fs): if not self.data: log.warning( "Could not serialize %s: No XBlock installed for '%s' tag.", - self.location, - self.location.block_type, + self.scope_ids.usage_id, + self.scope_ids.usage_id.block_type, ) return None @@ -297,6 +297,6 @@ def definition_to_xml(self, resource_fs): "Context: '{context}'" ).format( context=lines[line - 1][offset - 40:offset + 40], - loc=self.location, + loc=self.scope_ids.usage_id, ) - raise SerializationError(self.location, msg) from err + raise SerializationError(self.scope_ids.usage_id, msg) from err diff --git a/xblocks_contrib/common/xml_utils.py b/xblocks_contrib/common/xml_utils.py index 4c86abb3..77cb1f6c 100644 --- a/xblocks_contrib/common/xml_utils.py +++ b/xblocks_contrib/common/xml_utils.py @@ -486,12 +486,12 @@ def add_xml_to_node(self, node): aside.add_xml_to_node(aside_node) xml_object.append(aside_node) - not_to_clean_fields = self.metadata_to_not_to_clean.get(self.category, ()) + not_to_clean_fields = self.metadata_to_not_to_clean.get(self.scope_ids.block_type, ()) self.clean_metadata_from_xml(xml_object, excluded_fields=not_to_clean_fields) # Set the tag on both nodes so we get the file path right. - xml_object.tag = self.category - node.tag = self.category + xml_object.tag = self.scope_ids.block_type + node.tag = self.scope_ids.block_type # Add the non-inherited metadata for attr in sorted(own_metadata(self)): @@ -506,7 +506,7 @@ def add_xml_to_node(self, node): logging.exception( 'Failed to serialize metadata attribute %s with value %s in module %s. ' 'This could mean data loss!!!', - attr, val, self.url_name + attr, val, self.scope_ids.usage_id.block_id ) for key, value in self.xml_attributes.items(): @@ -515,8 +515,8 @@ def add_xml_to_node(self, node): if self.export_to_file(): # Write the definition to a file - url_path = name_to_pathname(self.url_name) - filepath = self._format_filepath(self.category, url_path) + url_path = name_to_pathname(self.scope_ids.usage_id.block_id) + filepath = self._format_filepath(self.scope_ids.block_type, url_path) self.runtime.export_fs.makedirs(os.path.dirname(filepath), recreate=True) with self.runtime.export_fs.open(filepath, 'wb') as fileobj: ElementTree(xml_object).write(fileobj, pretty_print=True, encoding='utf-8') @@ -531,16 +531,16 @@ def add_xml_to_node(self, node): # Do not override an existing value for the course. if not node.get('url_name'): - node.set('url_name', self.url_name) + node.set('url_name', self.scope_ids.usage_id.block_id) # We do not need to cater the `course` category here in xblocks_contrib, # because course export is handled in the edx-platform code. # Special case for course pointers: - # if self.category == 'course': + # if self.scope_ids.block_type == 'course': # # add org and course attributes on the pointer tag - # node.set('org', self.location.org) - # node.set('course', self.location.course) + # node.set('org', self.scope_ids.usage_id.org) + # node.set('course', self.scope_ids.usage_id.course) def definition_to_xml(self, resource_fs): """ diff --git a/xblocks_contrib/html/html.py b/xblocks_contrib/html/html.py index ab1d9fa3..4351e16b 100644 --- a/xblocks_contrib/html/html.py +++ b/xblocks_contrib/html/html.py @@ -206,7 +206,7 @@ def location(self, value): @property def url_name(self): - return self.location.block_id + return self.scope_ids.usage_id.block_id @property def xblock_kvs(self): @@ -325,7 +325,7 @@ def get_context(self): "module": self, "editable_metadata_fields": self.editable_metadata_fields, # pylint: disable=no-member "data": self.data, - "base_asset_url": self.get_base_url_path_for_course_assets(self.location.course_key), + "base_asset_url": self.get_base_url_path_for_course_assets(self.scope_ids.usage_id.course_key), "enable_latex_compiler": self.use_latex_compiler, "editor": self.editor, } @@ -546,8 +546,8 @@ def definition_to_xml(self, resource_fs): """ # Write html to file, return an empty tag - pathname = name_to_pathname(self.url_name) - filepath = "{category}/{pathname}.html".format(category=self.category, pathname=pathname) + pathname = name_to_pathname(self.scope_ids.usage_id.block_id) + filepath = "{category}/{pathname}.html".format(category=self.scope_ids.block_type, pathname=pathname) resource_fs.makedirs(os.path.dirname(filepath), recreate=True) with resource_fs.open(filepath, "wb") as filestream: diff --git a/xblocks_contrib/lti/lti.py b/xblocks_contrib/lti/lti.py index 0fbe3f9b..503f6ced 100644 --- a/xblocks_contrib/lti/lti.py +++ b/xblocks_contrib/lti/lti.py @@ -509,7 +509,7 @@ def get_context(self): # These parameters do not participate in OAuth signing. 'launch_url': self.launch_url.strip(), - 'element_id': self.location.html_id(), + 'element_id': self.scope_ids.usage_id.html_id(), 'element_class': self.scope_ids.block_type, 'open_in_a_new_page': self.open_in_a_new_page, 'display_name': self.display_name, @@ -743,7 +743,7 @@ def get_resource_link_id(self): i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id: makes resource_link_id to be unique among courses inside same system. """ - return str(parse.quote(f"{settings.LMS_BASE}-{self.location.html_id()}")) + return str(parse.quote(f"{settings.LMS_BASE}-{self.scope_ids.usage_id.html_id()}")) def get_lis_result_sourcedid(self): """ @@ -764,7 +764,7 @@ def get_course(self): """ Return course by course id. """ - return self.runtime.modulestore.get_course(self.location.course_key) + return self.runtime.modulestore.get_course(self.scope_ids.usage_id.course_key) @property def context_id(self): @@ -774,7 +774,7 @@ def context_id(self): context_id is an opaque identifier that uniquely identifies the context (e.g., a course) that contains the link being launched. """ - return str(self.location.course_key) + return str(self.scope_ids.usage_id.course_key) @property def role(self): @@ -871,8 +871,8 @@ def oauth_params(self, custom_parameters, client_key, client_secret): # Stubbing headers for now: log.info( "LTI block %s in course %s does not have oauth parameters correctly configured.", - self.location, - self.location.course_key, + self.scope_ids.usage_id, + self.scope_ids.usage_id.course_key, ) headers = { 'Content-Type': 'application/x-www-form-urlencoded', @@ -1026,4 +1026,4 @@ def definition_from_xml(cls, xml_object, system): def definition_to_xml(self, resource_fs): if self.data: return etree.fromstring(self.data) - return etree.Element(self.category) + return etree.Element(self.scope_ids.block_type) diff --git a/xblocks_contrib/poll/poll.py b/xblocks_contrib/poll/poll.py index 76e7d46e..10581cf7 100644 --- a/xblocks_contrib/poll/poll.py +++ b/xblocks_contrib/poll/poll.py @@ -121,11 +121,11 @@ def xblock_kvs(self): @property def url_name(self): - return self.location.block_id + return self.scope_ids.usage_id.block_id @property def course_id(self): - return self.location.course_key + return self.scope_ids.usage_id.course_key @property def category(self): @@ -298,7 +298,7 @@ def get_explicitly_set_fields_by_scope(self, scope=Scope.content): result[field.name] = field.read_json(self) except TypeError as exception: exception_message = "{message}, Block-location:{location}, Field-name:{field_name}".format( - message=str(exception), location=str(self.location), field_name=field.name + message=str(exception), location=str(self.scope_ids.usage_id), field_name=field.name ) raise TypeError(exception_message) # pylint: disable=raise-missing-from return result diff --git a/xblocks_contrib/word_cloud/word_cloud.py b/xblocks_contrib/word_cloud/word_cloud.py index 26c3cedd..5351e134 100644 --- a/xblocks_contrib/word_cloud/word_cloud.py +++ b/xblocks_contrib/word_cloud/word_cloud.py @@ -342,4 +342,4 @@ def definition_from_xml(cls, xml_object, system): def definition_to_xml(self, resource_fs): if self.data: return etree.fromstring(self.data) - return etree.Element(self.category) + return etree.Element(self.scope_ids.block_type)