Skip to content

Commit 22b71fc

Browse files
committed
chore: replace XModuleMixin properties with block fields
1 parent ea99bd8 commit 22b71fc

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
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
@@ -206,7 +206,7 @@ def location(self, value):
206206

207207
@property
208208
def url_name(self):
209-
return self.location.block_id
209+
return self.scope_ids.usage_id.block_id
210210

211211
@property
212212
def xblock_kvs(self):
@@ -325,7 +325,7 @@ def get_context(self):
325325
"module": self,
326326
"editable_metadata_fields": self.editable_metadata_fields, # pylint: disable=no-member
327327
"data": self.data,
328-
"base_asset_url": self.get_base_url_path_for_course_assets(self.location.course_key),
328+
"base_asset_url": self.get_base_url_path_for_course_assets(self.scope_ids.usage_id.course_key),
329329
"enable_latex_compiler": self.use_latex_compiler,
330330
"editor": self.editor,
331331
}
@@ -546,8 +546,8 @@ def definition_to_xml(self, resource_fs):
546546
"""
547547

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

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

xblocks_contrib/lti/lti.py

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

510510
# These parameters do not participate in OAuth signing.
511511
'launch_url': self.launch_url.strip(),
512-
'element_id': self.location.html_id(),
512+
'element_id': self.scope_ids.usage_id.html_id(),
513513
'element_class': self.scope_ids.block_type,
514514
'open_in_a_new_page': self.open_in_a_new_page,
515515
'display_name': self.display_name,
@@ -743,7 +743,7 @@ def get_resource_link_id(self):
743743
i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id:
744744
makes resource_link_id to be unique among courses inside same system.
745745
"""
746-
return str(parse.quote(f"{settings.LMS_BASE}-{self.location.html_id()}"))
746+
return str(parse.quote(f"{settings.LMS_BASE}-{self.scope_ids.usage_id.html_id()}"))
747747

748748
def get_lis_result_sourcedid(self):
749749
"""
@@ -764,7 +764,7 @@ def get_course(self):
764764
"""
765765
Return course by course id.
766766
"""
767-
return self.runtime.modulestore.get_course(self.location.course_key)
767+
return self.runtime.modulestore.get_course(self.scope_ids.usage_id.course_key)
768768

769769
@property
770770
def context_id(self):
@@ -774,7 +774,7 @@ def context_id(self):
774774
context_id is an opaque identifier that uniquely identifies the context (e.g., a course)
775775
that contains the link being launched.
776776
"""
777-
return str(self.location.course_key)
777+
return str(self.scope_ids.usage_id.course_key)
778778

779779
@property
780780
def role(self):
@@ -871,8 +871,8 @@ def oauth_params(self, custom_parameters, client_key, client_secret):
871871
# Stubbing headers for now:
872872
log.info(
873873
"LTI block %s in course %s does not have oauth parameters correctly configured.",
874-
self.location,
875-
self.location.course_key,
874+
self.scope_ids.usage_id,
875+
self.scope_ids.usage_id.course_key,
876876
)
877877
headers = {
878878
'Content-Type': 'application/x-www-form-urlencoded',
@@ -1026,4 +1026,4 @@ def definition_from_xml(cls, xml_object, system):
10261026
def definition_to_xml(self, resource_fs):
10271027
if self.data:
10281028
return etree.fromstring(self.data)
1029-
return etree.Element(self.category)
1029+
return etree.Element(self.scope_ids.block_type)

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)