summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2019-12-02 10:18:33 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2019-12-04 13:06:54 +0000
commite237ba26f7fbe687ff87ed5311549671d5682515 (patch)
tree2bb0a4c450eca5ea3bc7fbc5e1eba30d011822be
parent96ab29c9873ee3d0f603068c6bc0c2d4056a3081 (diff)
[IMP]: web, tools: static inheritance do not disclose t-inherit* directives
Before this commit, when a template was inheriting from another the template mentionned its t-inherit This has been deemed overkill as the information is irrelevant to the caller i.e. the caller just wants the template and doesn't care how they've been computed After this commit, only t-name and attributes not related with inheritance are disclosed [FIX]: base: static inheritance propagates other attributes When doing a inherit in primary mode, the original attributes on the root node of the inheriting template were not propagated After this commit they are
-rw-r--r--addons/web/controllers/main.py5
-rw-r--r--addons/web/tests/test_serving_base.py92
-rw-r--r--odoo/tools/template_inheritance.py7
3 files changed, 93 insertions, 11 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 0ae52465604..06b146c318f 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -517,8 +517,9 @@ class HomeStaticTemplateHelpers(object):
inherited_template = apply_inheritance_specs(parent_tree, xpaths)
if inherit_mode == self.PRIMARY_MODE: # New template_tree: A' = B(A)
- inherited_template.set(self.NAME_TEMPLATE_DIRECTIVE, template_name)
- inherited_template.set(self.STATIC_INHERIT_DIRECTIVE, template_tree.attrib[self.STATIC_INHERIT_DIRECTIVE])
+ for attr_name, attr_val in template_tree.attrib.items():
+ if attr_name not in ('t-inherit', 't-inherit-mode'):
+ inherited_template.set(attr_name, attr_val)
if self.debug:
self._remove_inheritance_comments(inherited_template)
self.template_dict[addon][template_name] = inherited_template
diff --git a/addons/web/tests/test_serving_base.py b/addons/web/tests/test_serving_base.py
index 87c01d748dc..1279caf016a 100644
--- a/addons/web/tests/test_serving_base.py
+++ b/addons/web/tests/test_serving_base.py
@@ -144,7 +144,7 @@ class TestStaticInheritance(BaseCase):
<!-- Modified by anonymous_template_2 from module_2 -->
<div>And I learned how to get along</div>
</t>
- <form t-name="template_2_1" random-attr="gloria" t-inherit="module_1.template_1_1">
+ <form t-name="template_2_1" random-attr="gloria">
<div>At first I was afraid</div>
<div>I was petrified</div>
<div>But then I spent so many nights thinking how you did me wrong</div>
@@ -158,6 +158,86 @@ class TestStaticInheritance(BaseCase):
self.assertXMLEqual(contents, expected)
+ def test_static_inheritance_02(self):
+ self.template_files = {
+ 'module_1_file_1': b'''
+ <templates id="template" xml:space="preserve">
+ <form t-name="template_1_1" random-attr="gloria">
+ <div>At first I was afraid</div>
+ <div>Kept thinking I could never live without you by my side</div>
+ </form>
+ <form t-name="template_1_2" t-inherit="template_1_1" added="true">
+ <xpath expr="//div[1]" position="after">
+ <div>I was petrified</div>
+ </xpath>
+ </form>
+ </templates>
+ '''
+ }
+ self.modules = [
+ ('module_1_file_1', None, 'module_1'),
+ ]
+ contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True)
+ expected = b"""
+ <templates>
+ <form t-name="template_1_1" random-attr="gloria">
+ <div>At first I was afraid</div>
+ <div>Kept thinking I could never live without you by my side</div>
+ </form>
+ <form t-name="template_1_2" random-attr="gloria" added="true">
+ <div>At first I was afraid</div>
+ <div>I was petrified</div>
+ <div>Kept thinking I could never live without you by my side</div>
+ </form>
+ </templates>
+ """
+
+ self.assertXMLEqual(contents, expected)
+
+ def test_static_inheritance_03(self):
+ self.maxDiff = None
+ self.template_files = {
+ 'module_1_file_1': b'''
+ <templates id="template" xml:space="preserve">
+ <form t-name="template_1_1">
+ <div>At first I was afraid</div>
+ <div>Kept thinking I could never live without you by my side</div>
+ </form>
+ <form t-name="template_1_2" t-inherit="template_1_1" added="true">
+ <xpath expr="//div[1]" position="after">
+ <div>I was petrified</div>
+ </xpath>
+ </form>
+ <form t-name="template_1_3" t-inherit="template_1_2" added="false" other="here">
+ <xpath expr="//div[2]" position="replace"/>
+ </form>
+ </templates>
+ '''
+ }
+ self.modules = [
+ ('module_1_file_1', None, 'module_1'),
+ ]
+ contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True)
+ expected = b"""
+ <templates>
+ <form t-name="template_1_1">
+ <div>At first I was afraid</div>
+ <div>Kept thinking I could never live without you by my side</div>
+ </form>
+ <form t-name="template_1_2" added="true">
+ <div>At first I was afraid</div>
+ <div>I was petrified</div>
+ <div>Kept thinking I could never live without you by my side</div>
+ </form>
+ <form t-name="template_1_3" added="false" other="here">
+ <div>At first I was afraid</div>
+ <div>Kept thinking I could never live without you by my side</div>
+ </form>
+ </templates>
+ """
+
+ self.assertXMLEqual(contents, expected)
+
def test_static_inheritance_in_same_module(self):
self.modules = [
('module_1_file_1', None, 'module_1'),
@@ -191,7 +271,7 @@ class TestStaticInheritance(BaseCase):
<div>At first I was afraid</div>
<div>Kept thinking I could never live without you by my side</div>
</form>
- <form t-name="template_1_2" t-inherit="template_1_1">
+ <form t-name="template_1_2">
<div>At first I was afraid</div>
<div>I was petrified</div>
<div>Kept thinking I could never live without you by my side</div>
@@ -228,7 +308,7 @@ class TestStaticInheritance(BaseCase):
<div>At first I was afraid</div>
<div>Kept thinking I could never live without you by my side</div>
</form>
- <form t-name="template_1_2" t-inherit="template_1_1">
+ <form t-name="template_1_2">
<div>At first I was afraid</div>
<div>I was petrified</div>
<div>Kept thinking I could never live without you by my side</div>
@@ -271,7 +351,7 @@ class TestStaticInheritance(BaseCase):
<div>I was petrified</div>
<div>Kept thinking I could never live without you by my side</div>
</form>
- <form t-name="template_1_3" t-inherit="template_1_1">
+ <form t-name="template_1_3">
<div>At first I was afraid</div>
<div>I was petrified</div>
<div>Kept thinking I could never live without you by my side</div>
@@ -630,7 +710,7 @@ class TestStaticInheritance(BaseCase):
<div>At first I was afraid</div>
<form>Inner Form</form>
</form>
- <div t-name="template_1_2" t-inherit="template_1_1">
+ <div t-name="template_1_2">
Form replacer
</div>
</templates>
@@ -670,7 +750,7 @@ class TestStaticInheritance(BaseCase):
<form t-name="template_1_1" random-attr="gloria">
<div>At first I was afraid</div>
</form>
- <div overriden-attr="overriden" t-name="template_1_2" t-inherit="template_1_1">
+ <div overriden-attr="overriden" t-name="template_1_2">
And I grew strong
<p>And I learned how to get along</p>
</div>
diff --git a/odoo/tools/template_inheritance.py b/odoo/tools/template_inheritance.py
index 77f738f2e2a..ad497d99bb7 100644
--- a/odoo/tools/template_inheritance.py
+++ b/odoo/tools/template_inheritance.py
@@ -138,9 +138,10 @@ def apply_inheritance_specs(source, specs_tree, inherit_branding=False, pre_loca
else:
comment = content
source = copy.deepcopy(spec_content)
- for attr in ('t-name', 't-inherit'):
- if node.get(attr):
- source.set(attr, node.get(attr))
+ # only keep the t-name of a template root node
+ t_name = node.get('t-name')
+ if t_name:
+ source.set('t-name', t_name)
if comment is not None:
text = source.text
source.text = None