[IMP] unbrand t-raw and t-esc as keeping them branded makes very little sense
they can't be edited in any situation bzr revid: xmo@openerp.com-20140225110046-90rdevm13pp4m51s
This commit is contained in:
parent
bb795e929d
commit
1b2be9be76
|
@ -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
|
||||
|
|
|
@ -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': """<root>
|
||||
<item><span t-esc="foo"/></item>
|
||||
</root>""",
|
||||
})
|
||||
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue