diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index da2618ea8f5..8c4eb965edb 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -728,6 +728,18 @@ class view(osv.osv): def clear_cache(self): self.read_template.clear_cache(self) + def _contains_branded(self, node): + return node.tag == 't'\ + or 't-raw' in node.attrib\ + or any(self.is_node_branded(child) for child in node.iterdescendants()) + + def _pop_view_branding(self, element): + distributed_branding = dict( + (attribute, element.attrib.pop(attribute)) + for attribute in MOVABLE_BRANDING + if element.get(attribute)) + return distributed_branding + def distribute_branding(self, e, branding=None, parent_xpath='', index_map=misc.ConstantMapping(1)): if e.get('t-ignore') or e.tag == 'head': @@ -742,15 +754,15 @@ class view(osv.osv): e.set('data-oe-xpath', node_path) if not e.get('data-oe-model'): return - # if a branded element contains branded elements distribute own - # branding to children unless it's t-raw, then just remove branding - # on current element - if e.tag == 't' or 't-raw' in e.attrib or \ - any(self.is_node_branded(child) for child in e.iterdescendants()): - distributed_branding = dict( - (attribute, e.attrib.pop(attribute)) - for attribute in MOVABLE_BRANDING - if e.get(attribute)) + if set(('t-esc', 't-escf', 't-raw', 't-rawf')).intersection(e.attrib): + # nodes which fully generate their content and have no reason to + # be branded because they can not sensibly be edited + self._pop_view_branding(e) + elif self._contains_branded(e): + # if a branded element contains branded elements distribute own + # branding to children unless it's t-raw, then just remove branding + # on current element + distributed_branding = self._pop_view_branding(e) if 't-raw' not in e.attrib: # TODO: collections.Counter if remove p2.6 compat diff --git a/openerp/addons/base/tests/test_views.py b/openerp/addons/base/tests/test_views.py index 414285f5fc7..82a0980853f 100644 --- a/openerp/addons/base/tests/test_views.py +++ b/openerp/addons/base/tests/test_views.py @@ -545,10 +545,23 @@ class TestTemplating(ViewCase): ) ) - @unittest2.expectedFailure def test_esc_no_branding(self): - self.fail("View branding should be removed on t-esc or other terminal " - "branded node with no content (r-raw, *f)") + Views = self.registry('ir.ui.view') + id = Views.create(self.cr, self.uid, { + 'name': "Base View", + 'type': 'qweb', + 'arch': """ + + """, + }) + + arch_string = Views.read_combined( + self.cr, self.uid, id, fields=['arch'], + context={'inherit_branding': True})['arch'] + arch = ET.fromstring(arch_string) + Views.distribute_branding(arch) + + self.assertEqual(arch, E.root(E.item(E.span({'t-esc': "foo"})))) @unittest2.expectedFailure def test_ignore_unbrand(self):