Skip to content

Commit 9a0ff81

Browse files
committed
chore: replace XModuleMixin properties with block fields
1 parent 28c7617 commit 9a0ff81

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

xblocks_contrib/annotatable/annotatable.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SerializationError(Exception):
3131
"""
3232
def __init__(self, location, msg):
3333
super().__init__(msg)
34-
self.location = location
34+
self.scope_ids.usage_id = location
3535

3636

3737
@XBlock.needs("i18n")
@@ -279,8 +279,8 @@ def definition_to_xml(self, resource_fs):
279279
if not self.data:
280280
log.warning(
281281
"Could not serialize %s: No XBlock installed for '%s' tag.",
282-
self.location,
283-
self.location.block_type,
282+
self.scope_ids.usage_id,
283+
self.scope_ids.usage_id.block_type,
284284
)
285285
return None
286286

@@ -297,6 +297,6 @@ def definition_to_xml(self, resource_fs):
297297
"Context: '{context}'"
298298
).format(
299299
context=lines[line - 1][offset - 40:offset + 40],
300-
loc=self.location,
300+
loc=self.scope_ids.usage_id,
301301
)
302-
raise SerializationError(self.location, msg) from err
302+
raise SerializationError(self.scope_ids.usage_id, msg) from err

xblocks_contrib/common/xml_utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,12 @@ def add_xml_to_node(self, node):
486486
aside.add_xml_to_node(aside_node)
487487
xml_object.append(aside_node)
488488

489-
not_to_clean_fields = self.metadata_to_not_to_clean.get(self.category, ())
489+
not_to_clean_fields = self.metadata_to_not_to_clean.get(self.scope_ids.block_type, ())
490490
self.clean_metadata_from_xml(xml_object, excluded_fields=not_to_clean_fields)
491491

492492
# Set the tag on both nodes so we get the file path right.
493-
xml_object.tag = self.category
494-
node.tag = self.category
493+
xml_object.tag = self.scope_ids.block_type
494+
node.tag = self.scope_ids.block_type
495495

496496
# Add the non-inherited metadata
497497
for attr in sorted(own_metadata(self)):
@@ -506,7 +506,7 @@ def add_xml_to_node(self, node):
506506
logging.exception(
507507
'Failed to serialize metadata attribute %s with value %s in module %s. '
508508
'This could mean data loss!!!',
509-
attr, val, self.url_name
509+
attr, val, self.scope_ids.usage_id.block_id
510510
)
511511

512512
for key, value in self.xml_attributes.items():
@@ -515,8 +515,8 @@ def add_xml_to_node(self, node):
515515

516516
if self.export_to_file():
517517
# Write the definition to a file
518-
url_path = name_to_pathname(self.url_name)
519-
filepath = self._format_filepath(self.category, url_path)
518+
url_path = name_to_pathname(self.scope_ids.usage_id.block_id)
519+
filepath = self._format_filepath(self.scope_ids.block_type, url_path)
520520
self.runtime.export_fs.makedirs(os.path.dirname(filepath), recreate=True)
521521
with self.runtime.export_fs.open(filepath, 'wb') as fileobj:
522522
ElementTree(xml_object).write(fileobj, pretty_print=True, encoding='utf-8')
@@ -531,16 +531,16 @@ def add_xml_to_node(self, node):
531531

532532
# Do not override an existing value for the course.
533533
if not node.get('url_name'):
534-
node.set('url_name', self.url_name)
534+
node.set('url_name', self.scope_ids.usage_id.block_id)
535535

536536
# We do not need to cater the `course` category here in xblocks_contrib,
537537
# because course export is handled in the edx-platform code.
538538

539539
# Special case for course pointers:
540-
# if self.category == 'course':
540+
# if self.scope_ids.block_type == 'course':
541541
# # add org and course attributes on the pointer tag
542-
# node.set('org', self.location.org)
543-
# node.set('course', self.location.course)
542+
# node.set('org', self.scope_ids.usage_id.org)
543+
# node.set('course', self.scope_ids.usage_id.course)
544544

545545
def definition_to_xml(self, resource_fs):
546546
"""

xblocks_contrib/html/html.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def location(self, value):
205205

206206
@property
207207
def url_name(self):
208-
return self.location.block_id
208+
return self.scope_ids.usage_id.block_id
209209

210210
@property
211211
def xblock_kvs(self):
@@ -324,7 +324,7 @@ def get_context(self):
324324
"module": self,
325325
"editable_metadata_fields": self.editable_metadata_fields, # pylint: disable=no-member
326326
"data": self.data,
327-
"base_asset_url": self.get_base_url_path_for_course_assets(self.location.course_key),
327+
"base_asset_url": self.get_base_url_path_for_course_assets(self.scope_ids.usage_id.course_key),
328328
"enable_latex_compiler": self.use_latex_compiler,
329329
"editor": self.editor,
330330
}
@@ -545,8 +545,8 @@ def definition_to_xml(self, resource_fs):
545545
"""
546546

547547
# Write html to file, return an empty tag
548-
pathname = name_to_pathname(self.url_name)
549-
filepath = "{category}/{pathname}.html".format(category=self.category, pathname=pathname)
548+
pathname = name_to_pathname(self.scope_ids.usage_id.block_id)
549+
filepath = "{category}/{pathname}.html".format(category=self.scope_ids.block_type, pathname=pathname)
550550

551551
resource_fs.makedirs(os.path.dirname(filepath), recreate=True)
552552
with resource_fs.open(filepath, "wb") as filestream:

xblocks_contrib/lti/lti.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def get_context(self):
518518

519519
# These parameters do not participate in OAuth signing.
520520
'launch_url': self.launch_url.strip(),
521-
'element_id': self.location.html_id(),
521+
'element_id': self.scope_ids.usage_id.html_id(),
522522
'element_class': self.scope_ids.block_type,
523523
'open_in_a_new_page': self.open_in_a_new_page,
524524
'display_name': self.display_name,
@@ -752,7 +752,7 @@ def get_resource_link_id(self):
752752
i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id:
753753
makes resource_link_id to be unique among courses inside same system.
754754
"""
755-
return str(parse.quote(f"{settings.LMS_BASE}-{self.location.html_id()}"))
755+
return str(parse.quote(f"{settings.LMS_BASE}-{self.scope_ids.usage_id.html_id()}"))
756756

757757
def get_lis_result_sourcedid(self):
758758
"""
@@ -778,8 +778,8 @@ def get_course(self):
778778
In general, please do not add new code that access Modulestore, because it
779779
will not work in Learning Core. We do it here just to support a legacy feature.
780780
"""
781-
if isinstance(self.location.course_key, CourseKey):
782-
return self.runtime.modulestore.get_course(self.location.course_key)
781+
if isinstance(self.scope_ids.usage_id.course_key, CourseKey):
782+
return self.runtime.modulestore.get_course(self.scope_ids.usage_id.course_key)
783783
return None
784784

785785
@property
@@ -790,7 +790,7 @@ def context_id(self):
790790
context_id is an opaque identifier that uniquely identifies the context (e.g., a course)
791791
that contains the link being launched.
792792
"""
793-
return str(self.location.course_key)
793+
return str(self.scope_ids.usage_id.course_key)
794794

795795
@property
796796
def role(self):
@@ -887,8 +887,8 @@ def oauth_params(self, custom_parameters, client_key, client_secret):
887887
# Stubbing headers for now:
888888
log.info(
889889
"LTI block %s in course %s does not have oauth parameters correctly configured.",
890-
self.location,
891-
self.location.course_key,
890+
self.scope_ids.usage_id,
891+
self.scope_ids.usage_id.course_key,
892892
)
893893
headers = {
894894
'Content-Type': 'application/x-www-form-urlencoded',
@@ -1042,7 +1042,7 @@ def definition_from_xml(cls, xml_object, system):
10421042
def definition_to_xml(self, resource_fs):
10431043
if self.data:
10441044
return etree.fromstring(self.data)
1045-
return etree.Element(self.category)
1045+
return etree.Element(self.scope_ids.block_type)
10461046

10471047
def bind_for_student(self, user_id, wrappers=None):
10481048
"""

xblocks_contrib/poll/poll.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ def xblock_kvs(self):
121121

122122
@property
123123
def url_name(self):
124-
return self.location.block_id
124+
return self.scope_ids.usage_id.block_id
125125

126126
@property
127127
def course_id(self):
128-
return self.location.course_key
128+
return self.scope_ids.usage_id.course_key
129129

130130
@property
131131
def category(self):
@@ -298,7 +298,7 @@ def get_explicitly_set_fields_by_scope(self, scope=Scope.content):
298298
result[field.name] = field.read_json(self)
299299
except TypeError as exception:
300300
exception_message = "{message}, Block-location:{location}, Field-name:{field_name}".format(
301-
message=str(exception), location=str(self.location), field_name=field.name
301+
message=str(exception), location=str(self.scope_ids.usage_id), field_name=field.name
302302
)
303303
raise TypeError(exception_message) # pylint: disable=raise-missing-from
304304
return result

xblocks_contrib/word_cloud/word_cloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,4 @@ def definition_from_xml(cls, xml_object, system):
342342
def definition_to_xml(self, resource_fs):
343343
if self.data:
344344
return etree.fromstring(self.data)
345-
return etree.Element(self.category)
345+
return etree.Element(self.scope_ids.block_type)

0 commit comments

Comments
 (0)