From 013b009c2499edd0eaf727a628119dc02302b4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Thu, 29 Feb 2024 14:59:00 -0300 Subject: [PATCH] feat: add content tag serialization/deserialization --- drag_and_drop_v2/__init__.py | 2 +- drag_and_drop_v2/drag_and_drop_v2.py | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drag_and_drop_v2/__init__.py b/drag_and_drop_v2/__init__.py index 7b40bcd4..409f123d 100644 --- a/drag_and_drop_v2/__init__.py +++ b/drag_and_drop_v2/__init__.py @@ -1,4 +1,4 @@ """ Drag and Drop v2 XBlock """ from .drag_and_drop_v2 import DragAndDropBlock -__version__ = "3.4.0" +__version__ = "3.5.0" diff --git a/drag_and_drop_v2/drag_and_drop_v2.py b/drag_and_drop_v2/drag_and_drop_v2.py index a385d691..50e21267 100644 --- a/drag_and_drop_v2/drag_and_drop_v2.py +++ b/drag_and_drop_v2/drag_and_drop_v2.py @@ -252,6 +252,9 @@ class DragAndDropBlock( block_settings_key = 'drag-and-drop-v2' + xml_attributes = Dict(help="Map of unhandled xml attributes, used only for storage between import and export", + default={}, scope=Scope.settings) + @property def score(self): """ @@ -1387,3 +1390,30 @@ def index_dictionary(self): xblock_body["content_type"] = "Drag and Drop" return xblock_body + + def add_xml_to_node(self, node): + """ + Serialize the XBlock to XML for exporting. + """ + super().add_xml_to_node(node) + + # Serialize and add tag data if any + if hasattr(self, 'add_tags_to_node') and callable(self.add_tags_to_node): # pylint: disable=no-member + # This comes from TaggedBlockMixin + self.add_tags_to_node(node) # pylint: disable=no-member + + @classmethod + def parse_xml(cls, node, runtime, keys, id_generator): + """Instantiate XBlock object from runtime XML definition. + + Inherited by XBlock core. + """ + breakpoint() + block = super().parse_xml(node, runtime, keys, id_generator) + + # Deserialize and add tag data info to block if any + if hasattr(block, 'read_tags_from_node') and callable(block.read_tags_from_node): # pylint: disable=no-member + # This comes from TaggedBlockMixin + block.read_tags_from_node(node) # pylint: disable=no-member + + return block