Skip to content

Commit a5dc6ac

Browse files
committed
chore: update the key references
1 parent 9a0ff81 commit a5dc6ac

6 files changed

Lines changed: 34 additions & 54 deletions

File tree

xblocks_contrib/annotatable/annotatable.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class AnnotatableBlock(LegacyXmlMixin, XBlock):
9898

9999
@property
100100
def location(self):
101-
return self.scope_ids.usage_id
101+
return self.usage_key
102102

103103
@location.setter
104104
def location(self, value):
@@ -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.scope_ids.usage_id,
283-
self.scope_ids.usage_id.block_type,
282+
self.usage_key,
283+
self.usage_key.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.scope_ids.usage_id,
300+
loc=self.usage_key,
301301
)
302-
raise SerializationError(self.scope_ids.usage_id, msg) from err
302+
raise SerializationError(self.usage_key, msg) from err

xblocks_contrib/common/xml_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.scope_ids.usage_id.block_id
509+
attr, val, self.usage_key.block_id
510510
)
511511

512512
for key, value in self.xml_attributes.items():
@@ -515,7 +515,7 @@ 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.scope_ids.usage_id.block_id)
518+
url_path = name_to_pathname(self.usage_key.block_id)
519519
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:
@@ -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.scope_ids.usage_id.block_id)
534+
node.set('url_name', self.usage_key.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:
540540
# if self.scope_ids.block_type == 'course':
541541
# # add org and course attributes on the pointer tag
542-
# node.set('org', self.scope_ids.usage_id.org)
543-
# node.set('course', self.scope_ids.usage_id.course)
542+
# node.set('org', self.usage_key.org)
543+
# node.set('course', self.usage_key.course)
544544

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

xblocks_contrib/html/html.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ class HtmlBlockMixin(LegacyXmlMixin, XBlock):
189189

190190
@property
191191
def category(self):
192-
return self.scope_ids.block_type
192+
return self.usage_key.block_type
193193

194194
@property
195195
def location(self):
196-
return self.scope_ids.usage_id
196+
return self.usage_key
197197

198198
@location.setter
199199
def location(self, value):
@@ -205,7 +205,7 @@ def location(self, value):
205205

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

210210
@property
211211
def xblock_kvs(self):
@@ -264,7 +264,7 @@ def get_html(self):
264264
data = data.replace("%%USER_EMAIL%%", email)
265265

266266
# The course ID replacement is always safe to run.
267-
data = data.replace("%%COURSE_ID%%", str(self.scope_ids.usage_id.context_key))
267+
data = data.replace("%%COURSE_ID%%", str(self.context_key))
268268
return data
269269

270270
def studio_view(self, context=None):
@@ -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.scope_ids.usage_id.course_key),
327+
"base_asset_url": self.get_base_url_path_for_course_assets(self.context_key),
328328
"enable_latex_compiler": self.use_latex_compiler,
329329
"editor": self.editor,
330330
}
@@ -545,7 +545,7 @@ def definition_to_xml(self, resource_fs):
545545
"""
546546

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

551551
resource_fs.makedirs(os.path.dirname(filepath), recreate=True)

xblocks_contrib/lti/lti.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,15 @@ class LTIBlock(
386386
@property
387387
def category(self):
388388
"""Return the block type/category."""
389-
return self.scope_ids.block_type
389+
return self.usage_key.block_type
390390

391391
@property
392392
def url_name(self):
393-
return self.location.block_id
393+
return self.usage_key.block_id
394394

395395
@property
396396
def location(self):
397-
return self.scope_ids.usage_id
397+
return self.usage_key
398398

399399
@location.setter
400400
def location(self, value):
@@ -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.scope_ids.usage_id.html_id(),
521+
'element_id': self.usage_key.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.scope_ids.usage_id.html_id()}"))
755+
return str(parse.quote(f"{settings.LMS_BASE}-{self.usage_key.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.scope_ids.usage_id.course_key, CourseKey):
782-
return self.runtime.modulestore.get_course(self.scope_ids.usage_id.course_key)
781+
if isinstance(self.context_key, CourseKey):
782+
return self.runtime.modulestore.get_course(self.context_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.scope_ids.usage_id.course_key)
793+
return str(self.context_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.scope_ids.usage_id,
891-
self.scope_ids.usage_id.course_key,
890+
self.usage_key,
891+
self.context_key,
892892
)
893893
headers = {
894894
'Content-Type': 'application/x-www-form-urlencoded',

xblocks_contrib/poll/poll.py

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

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

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

130130
@property
131131
def category(self):
132-
return self.scope_ids.block_type
132+
return self.usage_key.block_type
133133

134134
@property
135135
def location(self):
136-
return self.scope_ids.usage_id
136+
return self.usage_key
137137

138138
@location.setter
139139
def location(self, value):
@@ -162,8 +162,8 @@ def student_view(self, _context):
162162
resource_loader.render_django_template(
163163
"templates/poll.html",
164164
{
165-
"element_id": self.scope_ids.usage_id.html_id(),
166-
"element_class": self.scope_ids.usage_id.block_type,
165+
"element_id": self.usage_key.html_id(),
166+
"element_class": self.usage_key.block_type,
167167
"configuration_json": self.dump_poll(),
168168
},
169169
i18n_service=self.runtime.service(self, "i18n"),
@@ -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.scope_ids.usage_id), field_name=field.name
301+
message=str(exception), location=str(self.usage_key), 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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,6 @@ class WordCloudBlock(StudioEditableXBlockMixin, LegacyXmlMixin, XBlock):
9999
scope=Scope.user_state_summary
100100
)
101101

102-
# @property
103-
# def category(self):
104-
# return self.scope_ids.block_type
105-
106-
# @property
107-
# def url_name(self):
108-
# return self.location.block_id
109-
110-
# @property
111-
# def location(self):
112-
# return self.scope_ids.usage_id
113-
114-
# @location.setter
115-
# def location(self, value):
116-
# assert isinstance(value, UsageKey)
117-
# self.scope_ids = self.scope_ids._replace(
118-
# def_id=value, # Note: assigning a UsageKey as def_id is OK in old mongo / import system but wrong in split
119-
# usage_id=value,
120-
# )
121-
122102
@staticmethod
123103
def workbench_scenarios():
124104
"""Create canned scenario for display in the workbench."""
@@ -342,4 +322,4 @@ def definition_from_xml(cls, xml_object, system):
342322
def definition_to_xml(self, resource_fs):
343323
if self.data:
344324
return etree.fromstring(self.data)
345-
return etree.Element(self.scope_ids.block_type)
325+
return etree.Element(self.usage_key.block_type)

0 commit comments

Comments
 (0)