Skip to content
Snippets Groups Projects
Commit 1c47f207 authored by Nicolas Lempereur's avatar Nicolas Lempereur
Browse files

[FIX] web_editor: update attribute of edition container


In most use case, when we edit the website we have a situation such as:

```
<div id="wrap" branding-attributes="...">
    <section class="mycontent">hi!</section>
</div>
```

When we modify a part, we replace all child nodes of the branded
element.

But if we had more complex content such as:

```
<div id="wrap">
    <section class="mycontent" branding-attributes="...">ho!</section>
    <t t-call-assets="web.assets_common" t-js="false" t-css="false"/>
</div>
```

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 `<section/>` node is saved, the possibly modified attributes
are lost.

Without the change, the added test fails with:

 '<div class="nice">hoi</div>' not found in '...<div>hoi</div>...' :
 saved element attributes are saved excluding branding ones

opw-2122947
closes #40345

closes odoo/odoo#40830

X-original-commit: 71b20a24
Signed-off-by: default avatarNicolas Lempereur (nle) <nle@odoo.com>
parent 70d856f2
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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'<t t-name="dummy"><div>hi</div><t esc="0"/></t>',
'type': 'qweb'
})
replacement = u'<div data-oe-id="55" class="nice">hoi</div>'
view.save(replacement, xpath='/t/div')
self.assertIn(
'<div class="nice">hoi</div>',
view.arch,
'saved element attributes are saved excluding branding ones'
)
def test_save_only_embedded(self):
Company = self.env['res.company']
company_id = 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment