Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions xblocks_contrib/annotatable/annotatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -98,7 +98,7 @@ class AnnotatableBlock(LegacyXmlMixin, XBlock):

@property
def location(self):
return self.scope_ids.usage_id
return self.usage_key

@location.setter
def location(self, value):
Expand Down Expand Up @@ -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.usage_key,
self.usage_key.block_type,
)
return None

Expand All @@ -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.usage_key,
)
raise SerializationError(self.location, msg) from err
raise SerializationError(self.usage_key, msg) from err
20 changes: 10 additions & 10 deletions xblocks_contrib/common/xml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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.usage_key.block_id
)

for key, value in self.xml_attributes.items():
Expand All @@ -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.usage_key.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')
Expand All @@ -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.usage_key.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.usage_key.org)
# node.set('course', self.usage_key.course)

def definition_to_xml(self, resource_fs):
"""
Expand Down
14 changes: 7 additions & 7 deletions xblocks_contrib/html/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ class HtmlBlockMixin(LegacyXmlMixin, XBlock):

@property
def category(self):
return self.scope_ids.block_type
return self.usage_key.block_type

@property
def location(self):
return self.scope_ids.usage_id
return self.usage_key

@location.setter
def location(self, value):
Expand All @@ -205,7 +205,7 @@ def location(self, value):

@property
def url_name(self):
return self.location.block_id
return self.usage_key.block_id

@property
def xblock_kvs(self):
Expand Down Expand Up @@ -264,7 +264,7 @@ def get_html(self):
data = data.replace("%%USER_EMAIL%%", email)

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

def studio_view(self, context=None):
Expand Down Expand Up @@ -324,7 +324,7 @@ def get_context(self):
"module": self,
"editable_metadata_fields": self.editable_metadata_fields,
"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.context_key),
"enable_latex_compiler": self.use_latex_compiler,
"editor": self.editor,
}
Expand Down Expand Up @@ -545,8 +545,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.usage_key.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:
Expand Down
22 changes: 11 additions & 11 deletions xblocks_contrib/lti/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ class LTIBlock(
@property
def category(self):
"""Return the block type/category."""
return self.scope_ids.block_type
return self.usage_key.block_type

@property
def url_name(self):
return self.location.block_id
return self.usage_key.block_id

@property
def location(self):
return self.scope_ids.usage_id
return self.usage_key

@location.setter
def location(self, value):
Expand Down Expand Up @@ -513,7 +513,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.usage_key.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,
Expand Down Expand Up @@ -747,7 +747,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.usage_key.html_id()}"))

def get_lis_result_sourcedid(self):
"""
Expand All @@ -773,8 +773,8 @@ def get_course(self):
In general, please do not add new code that access Modulestore, because it
will not work with openedx_content. We do it here just to support a legacy feature.
"""
if isinstance(self.location.course_key, CourseKey):
return self.runtime.modulestore.get_course(self.location.course_key)
if isinstance(self.context_key, CourseKey):
return self.runtime.modulestore.get_course(self.context_key)
return None

@property
Expand All @@ -785,7 +785,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.context_key)

@property
def role(self):
Expand Down Expand Up @@ -882,8 +882,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.usage_key,
self.context_key,
)
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down Expand Up @@ -1037,7 +1037,7 @@ 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)

def bind_for_student(self, user_id, wrappers=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions xblocks_contrib/lti/tests/test_lti_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ def mock_handler_url(

def test_resource_link_id(self):
with patch(
"xblocks_contrib.lti.lti.LTIBlock.location", new_callable=PropertyMock
"xblocks_contrib.lti.lti.LTIBlock.usage_key", new_callable=PropertyMock
):
self.xblock.location.html_id = (
self.xblock.usage_key.html_id = (
lambda: "i4x-2-3-lti-31de800015cf4afb973356dbe81496df"
)
expected_resource_link_id = str(parse.quote(self.unquoted_resource_link_id))
Expand Down
14 changes: 7 additions & 7 deletions xblocks_contrib/poll/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ def xblock_kvs(self):

@property
def url_name(self):
return self.location.block_id
return self.usage_key.block_id

@property
def course_id(self):
return self.location.course_key
return self.context_key

@property
def category(self):
return self.scope_ids.block_type
return self.usage_key.block_type

@property
def location(self):
return self.scope_ids.usage_id
return self.usage_key

@location.setter
def location(self, value):
Expand Down Expand Up @@ -162,8 +162,8 @@ def student_view(self, _context):
resource_loader.render_django_template(
"templates/poll.html",
{
"element_id": self.scope_ids.usage_id.html_id(),
"element_class": self.scope_ids.usage_id.block_type,
"element_id": self.usage_key.html_id(),
"element_class": self.usage_key.block_type,
"configuration_json": self.dump_poll(),
},
i18n_service=self.runtime.service(self, "i18n"),
Expand Down Expand Up @@ -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.usage_key), field_name=field.name
)
raise TypeError(exception_message) # pylint: disable=raise-missing-from
return result
Expand Down
22 changes: 1 addition & 21 deletions xblocks_contrib/word_cloud/word_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,6 @@ 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,
)

@staticmethod
def workbench_scenarios():
"""Create canned scenario for display in the workbench."""
Expand Down Expand Up @@ -342,4 +322,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.usage_key.block_type)
Loading