summaryrefslogtreecommitdiff
path: root/addons/web_editor/models/ir_qweb.py
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2020-08-18 14:34:21 +0000
committerLaurent Stukkens (LTU) <ltu@odoo.com>2020-08-18 17:39:29 +0000
commitfaf51a373b3f7d299a67604ea86bc3a852b15c1b (patch)
tree533d9270d832c935227177c166618b7eb0f7aecf /addons/web_editor/models/ir_qweb.py
parent08ed6afa2a6e509b834e1c5fa9f732574c8b2162 (diff)
[FIX] web_editor: make sure [data-snippet] is added on internal t-call
Since [1], an attribute is added on all snippet contents, on the main node, to be able to identify them and better support them. This is added thanks to the t-snippet or the t-snippet-call instruction. The problem was this was not working if the first node of the snippet definition is also a t-call to another sub template. This now works. [1]: https://github.com/odoo/odoo/commit/11c60739e4f4379a61581ed179bc7debbb5e91f9 task-2276740 PR #53175
Diffstat (limited to 'addons/web_editor/models/ir_qweb.py')
-rw-r--r--addons/web_editor/models/ir_qweb.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/addons/web_editor/models/ir_qweb.py b/addons/web_editor/models/ir_qweb.py
index 4afd778aa71..7bd21dff430 100644
--- a/addons/web_editor/models/ir_qweb.py
+++ b/addons/web_editor/models/ir_qweb.py
@@ -48,15 +48,27 @@ class QWeb(models.AbstractModel):
# compile directives
def _compile_node(self, el, options):
- if options.get('snippet-key') == options['template']:
- # Get the path of the template's content
- path = options['root'].getpath(el).replace('/t', '')
- # Only append the template key on template's first node.
- # If it already has a data-snippet it is a saved snippet.
- # Do not override it.
- size = len(path.split('/'))
- if size == 2 and 'data-snippet' not in el.attrib:
- el.attrib['data-snippet'] = options['template'].split('.', 1)[-1]
+ snippet_key = options.get('snippet-key')
+ if snippet_key == options['template'] \
+ or options.get('snippet-sub-call-key') == options['template']:
+ # Get the path of element to only consider the first node of the
+ # snippet template content (ignoring all ancestors t elements which
+ # are not t-call ones)
+ nb_real_elements_in_hierarchy = 0
+ node = el
+ while node is not None and nb_real_elements_in_hierarchy < 2:
+ if node.tag != 't' or 't-call' in node.attrib:
+ nb_real_elements_in_hierarchy += 1
+ node = node.getparent()
+ if nb_real_elements_in_hierarchy == 1:
+ # The first node might be a call to a sub template
+ sub_call = el.get('t-call')
+ if sub_call:
+ el.set('t-call-options', f"{{'snippet-key': '{snippet_key}', 'snippet-sub-call-key': '{sub_call}'}}")
+ # If it already has a data-snippet it is a saved snippet.
+ # Do not override it.
+ elif 'data-snippet' not in el.attrib:
+ el.attrib['data-snippet'] = snippet_key.split('.', 1)[-1]
return super()._compile_node(el, options)