diff --git a/openedx/core/lib/xblock_serializer/api.py b/openedx/core/lib/xblock_serializer/api.py index b23a45c13bb5..f9ded3dbc55b 100644 --- a/openedx/core/lib/xblock_serializer/api.py +++ b/openedx/core/lib/xblock_serializer/api.py @@ -2,7 +2,7 @@ Public python API for serializing XBlocks to OLX """ # pylint: disable=unused-import -from .block_serializer import StaticFile, XBlockSerializer, XBlockSerializerForLearningCore +from .block_serializer import StaticFile, XBlockSerializer def serialize_xblock_to_olx(block): @@ -32,4 +32,4 @@ def serialize_modulestore_block_for_learning_core(block): we have around how we should rewrite this (e.g. are we going to remove ?). """ - return XBlockSerializerForLearningCore(block) + return XBlockSerializer(block, write_url_name=False) diff --git a/openedx/core/lib/xblock_serializer/block_serializer.py b/openedx/core/lib/xblock_serializer/block_serializer.py index 56c7a9541006..fc9a43e0cf8c 100644 --- a/openedx/core/lib/xblock_serializer/block_serializer.py +++ b/openedx/core/lib/xblock_serializer/block_serializer.py @@ -158,77 +158,3 @@ def _serialize_html_block(self, block) -> etree.Element: escaped_block_data = block.data.replace("]]>", "]]>") olx_node.text = etree.CDATA(escaped_block_data) return olx_node - - -class XBlockSerializerForLearningCore(XBlockSerializer): - """ - This class will serialize an XBlock, producing: - (1) A new definition ID for use in Learning Core - (2) an XML string defining the XBlock and referencing the IDs of its - children using syntax (which doesn't actually - contain the OLX of its children, just refers to them, so you have to - separately serialize them.) - (3) a list of any static files required by the XBlock and their URL - """ - - def __init__(self, block, *args, **kwargs): - """ - Serialize an XBlock to an OLX string + supporting files, and store the - resulting data in this object. - """ - super().__init__(block, *args, **kwargs) - self.def_id = utils.learning_core_def_key_from_modulestore_usage_key(self.orig_block_key) - - def _serialize_block(self, block) -> etree.Element: - """ Serialize an XBlock to OLX/XML. """ - olx_node = super()._serialize_block(block) - # Apply some transformations to the OLX: - self._transform_olx(olx_node, usage_id=block.scope_ids.usage_id) - return olx_node - - def _serialize_children(self, block, parent_olx_node): - """ - Recursively serialize the children of XBlock 'block'. - Subclasses may override this. - """ - for child_id in block.children: - # In modulestore, the "definition key" is a MongoDB ObjectID - # kept in split's definitions table, which theoretically allows - # the same block to be used in many places (each with a unique - # usage key). However, that functionality is not exposed in - # Studio (other than via content libraries). So when we import - # into Learning Core, we assume that each usage is unique, don't - # generate a usage key, and create a new "definition key" from - # the original usage key. - # So modulestore usage key - # block-v1:A+B+C+type@html+block@introduction - # will become Learning Core definition key - # html+introduction - # - # If we needed the real definition key, we could get it via - # child = block.runtime.get_block(child_id) - # child_def_id = str(child.scope_ids.def_id) - # and then use - # - def_id = utils.learning_core_def_key_from_modulestore_usage_key(child_id) - parent_olx_node.append(parent_olx_node.makeelement("xblock-include", {"definition": def_id})) - - def _transform_olx(self, olx_node, usage_id): - """ - Apply transformations to the given OLX etree Node. - """ - # Remove 'url_name' - we store the definition key in the folder name - # that holds the OLX and the usage key elsewhere, so specifying it - # within the OLX file is redundant and can lead to issues if the file is - # copied and pasted elsewhere in the bundle with a new definition key. - olx_node.attrib.pop('url_name', None) - # Convert to the new tag/block - if olx_node.tag == 'vertical': - olx_node.tag = 'unit' - for key in olx_node.attrib.keys(): - if key not in ('display_name', 'url_name'): - log.warning( - ' tag attribute "%s" will be ignored after conversion to (in %s)', - key, - str(usage_id) - )