From 919cc78be1004140b4ce9e4ac93acde487e81625 Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Mon, 21 Oct 2024 23:44:00 -0700 Subject: [PATCH] fix: Don't add 'x-is-pointer-node' to capa problems on paste --- cms/djangoapps/contentstore/helpers.py | 5 +++++ xmodule/xml_block.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/helpers.py b/cms/djangoapps/contentstore/helpers.py index 8ff1f1aa39..e40eddb6c9 100644 --- a/cms/djangoapps/contentstore/helpers.py +++ b/cms/djangoapps/contentstore/helpers.py @@ -7,6 +7,7 @@ import pathlib import urllib from lxml import etree from mimetypes import guess_type +import re from attrs import frozen, Factory from django.conf import settings @@ -447,6 +448,10 @@ def _import_xml_node_to_parent( temp_xblock = xblock_class.parse_xml(node_without_children, runtime, keys) child_nodes = list(node) + if issubclass(xblock_class, XmlMixin) and "x-is-pointer-node" in getattr(temp_xblock, "data", ""): + # Undo the "pointer node" hack if needed (e.g. for capa problems) + temp_xblock.data = re.sub(r'([^>]+) x-is-pointer-node="no"', r'\1', temp_xblock.data, count=1) + # Restore the original id_generator runtime.id_generator = original_id_generator diff --git a/xmodule/xml_block.py b/xmodule/xml_block.py index 2753d455ad..63dbedb17e 100644 --- a/xmodule/xml_block.py +++ b/xmodule/xml_block.py @@ -123,7 +123,11 @@ class XmlMixin: # places in the platform rely on it. 'course', 'org', 'url_name', 'filename', # Used for storing xml attributes between import and export, for roundtrips - 'xml_attributes') + 'xml_attributes', + # Used by _import_xml_node_to_parent in cms/djangoapps/contentstore/helpers.py to prevent + # XmlMixin from treating some XML nodes as "pointer nodes". + "x-is-pointer-node", + ) # This is a categories to fields map that contains the block category specific fields which should not be # cleaned and/or override while adding xml to node.