[IMP] qweb: don't use directive for static content

This commit is contained in:
Christophe Matthieu
2016-06-14 13:12:18 +02:00
parent 3cc44bef2a
commit 1e48122800
2 changed files with 29 additions and 4 deletions
+5
View File
@@ -70,3 +70,8 @@ class QWeb(orm.AbstractModel):
for name, value in atts.iteritems():
atts[name] = self._website_build_attribute(tagName, name, value, options, values)
return atts
def _is_static_node(self, el):
url_att = self.URL_ATTRS.get(el.tag)
cdn_att = self.CDN_TRIGGERS.get(el.tag)
return super(QWeb, self)._is_static_node(el) and (not url_att or not el.get(url_att)) and (not cdn_att or not el.get(cdn_att))
+24 -4
View File
@@ -634,11 +634,16 @@ class QWeb(object):
else:
body = []
options['iter_directives'] = iter(self._directives_eval_order() + [None])
if el.get("groups"):
el.set("t-groups", el.attrib.pop("groups"))
# if tag don't have qweb attributes don't use directives
if self._is_static_node(el):
return self._compile_static_node(el, options)
# create directive iterator
options['iter_directives'] = iter(self._directives_eval_order() + [None])
el.set('t-tag', el.tag)
if not (set(['t-esc', 't-raw', 't-field']) & set(el.attrib)):
el.set('t-content', 'True')
@@ -677,7 +682,7 @@ class QWeb(object):
ctx=ctx
)
# order and ignore
# order
def _directives_eval_order(self):
""" Should list all supported directives in the order in which they
@@ -703,7 +708,20 @@ class QWeb(object):
'esc', 'raw', 'content',
]
# compile directives
def _is_static_node(self, el):
return not any(att.startswith('t-') for att in el.attrib)
# compile
def _compile_static_node(self, el, options):
content = self._compile_directive_content(el, options)
if el.tag == 't':
return content
tag = u'<%s%s' % (el.tag, u''.join([u' %s="%s"' % (name, qweb_escape(value)) for name, value in el.attrib.iteritems()]))
if el.tag in self._void_elements:
return [self._append(ast.Str(tag + '/>'))] + content
else:
return [self._append(ast.Str(tag + '>'))] + content + [self._append(ast.Str('</%s>' % el.tag))]
def _serialize_static_attributes(self, el, options):
nodes = []
@@ -840,6 +858,8 @@ class QWeb(object):
body.append(self._append(ast.Str(u'</%s>' % el.tag)))
return body
# compile directives
def _compile_directive_debug(self, el, options):
debugger = el.attrib.pop('t-debug')
body = self._switch_directives(el, options)