Skip to content
Open
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
10 changes: 5 additions & 5 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 @@ -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.scope_ids.usage_id,
self.scope_ids.usage_id.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.scope_ids.usage_id,
)
raise SerializationError(self.location, msg) from err
raise SerializationError(self.scope_ids.usage_id, 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.scope_ids.usage_id.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.scope_ids.usage_id.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.scope_ids.usage_id.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.scope_ids.usage_id.org)
# node.set('course', self.scope_ids.usage_id.course)

def definition_to_xml(self, resource_fs):
"""
Expand Down
8 changes: 4 additions & 4 deletions xblocks_contrib/html/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def location(self, value):

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

@property
def xblock_kvs(self):
Expand Down Expand Up @@ -325,7 +325,7 @@ def get_context(self):
"module": self,
"editable_metadata_fields": self.editable_metadata_fields, # pylint: disable=no-member
"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.scope_ids.usage_id.course_key),
"enable_latex_compiler": self.use_latex_compiler,
"editor": self.editor,
}
Expand Down Expand Up @@ -546,8 +546,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.scope_ids.usage_id.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
14 changes: 7 additions & 7 deletions xblocks_contrib/lti/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,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.scope_ids.usage_id.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 @@ -743,7 +743,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.scope_ids.usage_id.html_id()}"))

def get_lis_result_sourcedid(self):
"""
Expand All @@ -764,7 +764,7 @@ def get_course(self):
"""
Return course by course id.
"""
return self.runtime.modulestore.get_course(self.location.course_key)
return self.runtime.modulestore.get_course(self.scope_ids.usage_id.course_key)

@property
def context_id(self):
Expand All @@ -774,7 +774,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.scope_ids.usage_id.course_key)

@property
def role(self):
Expand Down Expand Up @@ -871,8 +871,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.scope_ids.usage_id,
self.scope_ids.usage_id.course_key,
)
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down Expand Up @@ -1026,4 +1026,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.scope_ids.block_type)
6 changes: 3 additions & 3 deletions xblocks_contrib/poll/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def xblock_kvs(self):

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

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

@property
def category(self):
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.scope_ids.usage_id), field_name=field.name
)
raise TypeError(exception_message) # pylint: disable=raise-missing-from
return result
Expand Down
40 changes: 20 additions & 20 deletions xblocks_contrib/word_cloud/word_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ 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,
)
# @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():
Expand Down Expand Up @@ -342,4 +342,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.scope_ids.block_type)
Loading