From 1c47f2070b76ee6c06d0c65e6a3cfc7c1ccdfbfb Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 15 Nov 2019 13:38:07 +0000 Subject: [PATCH] [FIX] web_editor: update attribute of edition container In most use case, when we edit the website we have a situation such as: ```
hi!
``` When we modify a part, we replace all child nodes of the branded element. But if we had more complex content such as: ```
ho!
``` we have a t-call inside the div#wrap, so branding is distributed to child that could have attribute modified (eg. changing background). Then if `
` node is saved, the possibly modified attributes are lost. Without the change, the added test fails with: '
hoi
' not found in '...
hoi
...' : saved element attributes are saved excluding branding ones opw-2122947 closes #40345 closes odoo/odoo#40830 X-original-commit: 71b20a24c40ae9daa10076ab0fd656b043819cff Signed-off-by: Nicolas Lempereur (nle) --- addons/web_editor/models/ir_ui_view.py | 7 +++++++ addons/website/tests/test_views.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/addons/web_editor/models/ir_ui_view.py b/addons/web_editor/models/ir_ui_view.py index edda3ba6887..0d1100a0161 100644 --- a/addons/web_editor/models/ir_ui_view.py +++ b/addons/web_editor/models/ir_ui_view.py @@ -10,6 +10,8 @@ from odoo import api, fields, models _logger = logging.getLogger(__name__) +EDITING_ATTRIBUTES = ['data-oe-model', 'data-oe-id', 'data-oe-field', 'data-oe-xpath', 'data-note-id'] + class IrUiView(models.Model): _inherit = 'ir.ui.view' @@ -132,6 +134,11 @@ class IrUiView(models.Model): # Note: after a standard edition, the tail *must not* be replaced if replace_tail: root.tail = replacement.tail + # update attributes + root.attrib.clear() + root.attrib.update(replacement.attrib) + for attribute in EDITING_ATTRIBUTES: + root.attrib.pop(attribute, None) # replace all children del root[:] for child in replacement: diff --git a/addons/website/tests/test_views.py b/addons/website/tests/test_views.py index d99e3c84e16..81b180fb1de 100644 --- a/addons/website/tests/test_views.py +++ b/addons/website/tests/test_views.py @@ -221,6 +221,20 @@ class TestViewSaving(common.TransactionCase): 'text node characters wrongly unescaped when rendering' ) + def test_save_node_with_attr(self): + """ Test saving node with saved element changed attrs """ + view = self.env['ir.ui.view'].create({ + 'arch': u'
hi
', + 'type': 'qweb' + }) + replacement = u'
hoi
' + view.save(replacement, xpath='/t/div') + self.assertIn( + '
hoi
', + view.arch, + 'saved element attributes are saved excluding branding ones' + ) + def test_save_only_embedded(self): Company = self.env['res.company'] company_id = 1