[IMP] qweb: stop requiring t-name-flagged sub-node
QWeb's rendering currently *requires* that when loading a document instead of rendering the document itself it will render a sub-node with a properly labeled t-name. If a view is invoked by id, ir.qweb will look for a child with a t-name and fix up that t-name such that the base qweb object will find and render it. This feature mostly exists for JS compatibility (because a single document can contain multiple cross-linkable templates, and it was useful for cross-implementation tests though I'm not sue they're even checked anymore), and the <template> tag kinda took care of it, however with a more proper qweb view it becomes more of a liability / pain in the ass. Note: turns out there are bits of javascript which read server templates (???) and need to be altered to correctly handle the lack of <templates> wrapping.
This commit is contained in:
@@ -549,6 +549,9 @@ registry.addJob(function (wysiwyg) {
|
||||
context: options.context,
|
||||
},
|
||||
}).then(function (template) {
|
||||
if (!/^<templates>/.test(template)) {
|
||||
template = _.str.sprintf('<templates>%s</templates>', template);
|
||||
}
|
||||
QWeb.add_template(template);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -45,6 +45,9 @@ var ThemeCustomizeDialog = Dialog.extend({
|
||||
method: 'read_template',
|
||||
args: ['website.theme_customize'],
|
||||
}).then(function (data) {
|
||||
if (!/^<templates>/.test(data)) {
|
||||
data = _.str.sprintf('<templates>%s</templates>', data);
|
||||
}
|
||||
return core.qweb.add_template(data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,11 +129,11 @@ class IrQWeb(models.AbstractModel, QWeb):
|
||||
return view.inherit_id is not None
|
||||
|
||||
if isinstance(name, int) or is_child_view(name):
|
||||
for node in etree.fromstring(template):
|
||||
view = etree.fromstring(template)
|
||||
for node in view:
|
||||
if node.get('t-name'):
|
||||
node.set('t-name', str(name))
|
||||
return node.getparent()
|
||||
return None # trigger "template not found" in QWeb
|
||||
return view
|
||||
else:
|
||||
return template
|
||||
|
||||
|
||||
@@ -1161,8 +1161,7 @@ actual arch.
|
||||
arch = self.browse(view_id).read_combined(['arch'])['arch']
|
||||
arch_tree = etree.fromstring(arch)
|
||||
self.distribute_branding(arch_tree)
|
||||
root = E.templates(arch_tree)
|
||||
arch = etree.tostring(root, encoding='unicode')
|
||||
arch = etree.tostring(arch_tree, encoding='unicode')
|
||||
return arch
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -358,20 +358,21 @@ class QWeb(object):
|
||||
except Exception as e:
|
||||
raise QWebException("load could not load template", name=template)
|
||||
|
||||
if document is not None:
|
||||
if isinstance(document, etree._Element):
|
||||
element = document
|
||||
document = etree.tostring(document)
|
||||
elif not document.strip().startswith('<') and os.path.exists(document):
|
||||
element = etree.parse(document).getroot()
|
||||
else:
|
||||
element = etree.fromstring(document)
|
||||
if document is None:
|
||||
raise QWebException("Template not found", name=template)
|
||||
|
||||
for node in element:
|
||||
if node.get('t-name') == str(template):
|
||||
return (node, document)
|
||||
if isinstance(document, etree._Element):
|
||||
element = document
|
||||
document = etree.tostring(document)
|
||||
elif not document.strip().startswith('<') and os.path.exists(document):
|
||||
element = etree.parse(document).getroot()
|
||||
else:
|
||||
element = etree.fromstring(document)
|
||||
|
||||
raise QWebException("Template not found", name=template)
|
||||
for node in element:
|
||||
if node.get('t-name') == str(template):
|
||||
return (node, document)
|
||||
return (element, document)
|
||||
|
||||
def load(self, template, options):
|
||||
""" Load a given template. """
|
||||
|
||||
Reference in New Issue
Block a user