Skip to content

Commit e78be4e

Browse files
committed
chore: update the key references
1 parent 740d3d8 commit e78be4e

File tree

6 files changed

+34
-54
lines changed

6 files changed

+34
-54
lines changed

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,
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
@@ -381,15 +381,15 @@ class LTIBlock(
381381
@property
382382
def category(self):
383383
"""Return the block type/category."""
384-
return self.scope_ids.block_type
384+
return self.usage_key.block_type
385385

386386
@property
387387
def url_name(self):
388-
return self.location.block_id
388+
return self.usage_key.block_id
389389

390390
@property
391391
def location(self):
392-
return self.scope_ids.usage_id
392+
return self.usage_key
393393

394394
@location.setter
395395
def location(self, value):
@@ -513,7 +513,7 @@ def get_context(self):
513513

514514
# These parameters do not participate in OAuth signing.
515515
'launch_url': self.launch_url.strip(),
516-
'element_id': self.scope_ids.usage_id.html_id(),
516+
'element_id': self.usage_key.html_id(),
517517
'element_class': self.scope_ids.block_type,
518518
'open_in_a_new_page': self.open_in_a_new_page,
519519
'display_name': self.display_name,
@@ -747,7 +747,7 @@ def get_resource_link_id(self):
747747
i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id:
748748
makes resource_link_id to be unique among courses inside same system.
749749
"""
750-
return str(parse.quote(f"{settings.LMS_BASE}-{self.scope_ids.usage_id.html_id()}"))
750+
return str(parse.quote(f"{settings.LMS_BASE}-{self.usage_key.html_id()}"))
751751

752752
def get_lis_result_sourcedid(self):
753753
"""
@@ -773,8 +773,8 @@ def get_course(self):
773773
In general, please do not add new code that access Modulestore, because it
774774
will not work with openedx_content. We do it here just to support a legacy feature.
775775
"""
776-
if isinstance(self.scope_ids.usage_id.course_key, CourseKey):
777-
return self.runtime.modulestore.get_course(self.scope_ids.usage_id.course_key)
776+
if isinstance(self.context_key, CourseKey):
777+
return self.runtime.modulestore.get_course(self.context_key)
778778
return None
779779

780780
@property
@@ -785,7 +785,7 @@ def context_id(self):
785785
context_id is an opaque identifier that uniquely identifies the context (e.g., a course)
786786
that contains the link being launched.
787787
"""
788-
return str(self.scope_ids.usage_id.course_key)
788+
return str(self.context_key)
789789

790790
@property
791791
def role(self):
@@ -882,8 +882,8 @@ def oauth_params(self, custom_parameters, client_key, client_secret):
882882
# Stubbing headers for now:
883883
log.info(
884884
"LTI block %s in course %s does not have oauth parameters correctly configured.",
885-
self.scope_ids.usage_id,
886-
self.scope_ids.usage_id.course_key,
885+
self.usage_key,
886+
self.context_key,
887887
)
888888
headers = {
889889
'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)