Skip to content
Permalink
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 #40778

X-original-commit: 404fa81
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
  • Loading branch information
nle-odoo committed Nov 15, 2019
1 parent 0ef6c2b commit b56ac3504e0a9498eae73d6f5348d2daedabce58
Showing with 21 additions and 0 deletions.
  1. +7 −0 addons/web_editor/models/ir_ui_view.py
  2. +14 −0 addons/website/tests/test_views.py
@@ -11,6 +11,8 @@

_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'
@@ -81,6 +83,11 @@ def replace_arch_section(self, section_xpath, replacement):

root.text = replacement.text
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:
@@ -216,6 +216,20 @@ def test_save_escaped_text(self):
'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 comments on commit b56ac35

Please sign in to comment.
You can’t perform that action at this time.