From a67cd4c049fec67bb00580b2de8aad68dbf0eb57 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 25 Feb 2014 12:47:06 +0100 Subject: [PATCH] [FIX] t-ignore should remove injected sub-view branding below the ignore flag bzr revid: xmo@openerp.com-20140225114706-j8q44cubs59tuwby --- openerp/addons/base/ir/ir_ui_view.py | 5 +++ openerp/addons/base/tests/test_views.py | 49 +++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index 8c4eb965edb..360c5e37b31 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -743,6 +743,11 @@ class view(osv.osv): def distribute_branding(self, e, branding=None, parent_xpath='', index_map=misc.ConstantMapping(1)): if e.get('t-ignore') or e.tag == 'head': + # remove any view branding possibly injected by inheritance + attrs = set(MOVABLE_BRANDING) + for descendant in e.iterdescendants(tag=etree.Element): + if not attrs.intersection(descendant.attrib): continue + self._pop_view_branding(descendant) # TODO: find a better name and check if we have a string to boolean helper return diff --git a/openerp/addons/base/tests/test_views.py b/openerp/addons/base/tests/test_views.py index 82a0980853f..06030a84792 100644 --- a/openerp/addons/base/tests/test_views.py +++ b/openerp/addons/base/tests/test_views.py @@ -533,7 +533,7 @@ class TestTemplating(ViewCase): 'data-oe-xpath': '/xpath/item/content[1]', }), { 'order': '2', - 'data-oe-source-id': "159" + 'data-oe-source-id': str(id) }), E.item({ 'order': '1', @@ -563,9 +563,52 @@ class TestTemplating(ViewCase): self.assertEqual(arch, E.root(E.item(E.span({'t-esc': "foo"})))) - @unittest2.expectedFailure def test_ignore_unbrand(self): - self.fail("Branding should be removed from subviews of a t-ignore (?)") + Views = self.registry('ir.ui.view') + id = Views.create(self.cr, self.uid, { + 'name': "Base view", + 'type': 'qweb', + 'arch': """ + + + + """ + }) + id2 = Views.create(self.cr, self.uid, { + 'name': "Extension", + 'type': 'qweb', + 'inherit_id': id, + 'arch': """ + + bar + + """ + }) + + 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( + {'t-ignore': 'true', 'order': '1'}, + E.t({'t-esc': 'foo'}), + E.item( + {'order': '2', 'data-oe-source-id': str(id)}, + E.content( + {'t-att-href': 'foo'}, + "bar") + ) + ) + ), + "t-ignore should apply to injected sub-view branding, not just to" + " the main view's" + ) class test_views(ViewCase):