diff --git a/cms/djangoapps/contentstore/helpers.py b/cms/djangoapps/contentstore/helpers.py index e30e42add3e4..08e63a0fd62d 100644 --- a/cms/djangoapps/contentstore/helpers.py +++ b/cms/djangoapps/contentstore/helpers.py @@ -348,6 +348,7 @@ def _import_xml_node_to_parent( from cms.lib.xblock.tagging.tagged_block_mixin import TaggedBlockMixin if isinstance(new_xblock, TaggedBlockMixin): + new_xblock.read_tags_from_node(node) new_xblock.add_tags_from_xml() return new_xblock diff --git a/cms/lib/xblock/tagging/tagged_block_mixin.py b/cms/lib/xblock/tagging/tagged_block_mixin.py index da2ef3c8b57f..ce203b2286d1 100644 --- a/cms/lib/xblock/tagging/tagged_block_mixin.py +++ b/cms/lib/xblock/tagging/tagged_block_mixin.py @@ -3,11 +3,29 @@ """ from urllib.parse import quote, unquote +from xblock.fields import Scope, String + + +def _(text): + """ + A noop underscore function that marks strings for extraction. + """ + return text + class TaggedBlockMixin: """ Mixin containing XML serializing and parsing functionality for tagged blocks """ + + tags_v1 = String( + display_name=_("Tags v1"), + name="tags-v1", + help=_("Serialized content tags"), + default="", + scope=Scope.settings + ) + def studio_post_duplicate(self, store, source_item): """ Duplicates content tags from the source_item. @@ -17,7 +35,7 @@ def studio_post_duplicate(self, store, source_item): if hasattr(source_item, 'serialize_tag_data'): tags = source_item.serialize_tag_data() - self.xml_attributes['tags-v1'] = tags + self.tags_v1 = tags self.add_tags_from_xml() def serialize_tag_data(self): @@ -67,17 +85,17 @@ def read_tags_from_node(self, node): Deserialize and read tag data from node """ if 'tags-v1' in node.attrib: - self.xml_attributes['tags-v1'] = str(node.attrib['tags-v1']) + self.tags_v1 = str(node.attrib['tags-v1']) def add_tags_from_xml(self): """ - Parse and add tag data from xml_attributes + Parse and add tag data from tags_v1 field """ # This import is done here since we import and use TaggedBlockMixin in the cms settings, but the # content_tagging app wouldn't have loaded yet, so importing it outside causes an error from openedx.core.djangoapps.content_tagging.api import set_object_tags - tag_data = self.xml_attributes.get('tags-v1', None) if hasattr(self, 'xml_attributes') else None + tag_data = self.tags_v1 if not tag_data: return diff --git a/openedx/core/lib/xblock_serializer/block_serializer.py b/openedx/core/lib/xblock_serializer/block_serializer.py index deb46b07cecb..52288649aba6 100644 --- a/openedx/core/lib/xblock_serializer/block_serializer.py +++ b/openedx/core/lib/xblock_serializer/block_serializer.py @@ -89,6 +89,11 @@ def _serialize_normal_block(self, block) -> etree.Element: with filesystem.open(file_path, 'rb') as fh: data = fh.read() self.static_files.append(StaticFile(name=unit_file.name, data=data, url=None)) + + # Serialize and add tag data if any + if isinstance(block, TaggedBlockMixin): + block.add_tags_to_node(olx_node) + if block.has_children: self._serialize_children(block, olx_node) return olx_node