fix: Don't add 'x-is-pointer-node' to capa problems on paste

This commit is contained in:
Braden MacDonald
2024-10-21 23:44:00 -07:00
committed by Farhaan Bukhsh
parent a4d3bf91db
commit 919cc78be1
2 changed files with 10 additions and 1 deletions

View File

@@ -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

View File

@@ -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.