summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2014-10-09 17:29:43 +0200
committerFabien Meghazi <fme@openerp.com>2014-11-07 16:25:17 +0100
commit30e21de532aa1caa97cfbe566d068fb31355d76c (patch)
tree28eb548cdb7484dbdbc7d4d40d6e2b419ffb7b65
parent41274688299db4c25199e77ca1b4583fe4d6ea98 (diff)
[REM] Removed QWebContext.templates cache
Now rely solely on ir.ui.view#read_template()'s orm cache
-rw-r--r--openerp/addons/base/ir/ir_qweb.py50
1 files changed, 11 insertions, 39 deletions
diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py
index e9421aa3524..fdbdbea23e8 100644
--- a/openerp/addons/base/ir/ir_qweb.py
+++ b/openerp/addons/base/ir/ir_qweb.py
@@ -83,11 +83,10 @@ class FileSystemLoader(object):
return arch
class QWebContext(dict):
- def __init__(self, cr, uid, data, loader=None, templates=None, context=None):
+ def __init__(self, cr, uid, data, loader=None, context=None):
self.cr = cr
self.uid = uid
self.loader = loader
- self.templates = templates or {}
self.context = context
dic = dict(data)
super(QWebContext, self).__init__(dic)
@@ -106,7 +105,6 @@ class QWebContext(dict):
"""
return QWebContext(self.cr, self.uid, dict.copy(self),
loader=self.loader,
- templates=self.templates,
context=self.context)
def __copy__(self):
@@ -163,50 +161,24 @@ class QWeb(orm.AbstractModel):
def register_tag(self, tag, func):
self._render_tag[tag] = func
- def add_template(self, qwebcontext, name, node):
- """Add a parsed template in the context. Used to preprocess templates."""
- qwebcontext.templates[name] = node
-
- def load_document(self, document, res_id, qwebcontext):
- """
- Loads an XML document and installs any contained template in the engine
+ def get_template(self, name, qwebcontext):
+ origin_template = qwebcontext.get('__caller__') or qwebcontext['__stack__'][0]
+ try:
+ document = qwebcontext.loader(name)
+ except ValueError:
+ raise_qweb_exception(QWebTemplateNotFound, message="Loader could not find template %r" % name, template=origin_template)
- :type document: a parsed lxml.etree element, an unparsed XML document
- (as a string) or the path of an XML file to load
- """
- if not isinstance(document, basestring):
- # assume lxml.etree.Element
+ if hasattr(document, 'documentElement'):
dom = document
elif document.startswith("<?xml"):
dom = etree.fromstring(document)
else:
dom = etree.parse(document).getroot()
+ res_id = isinstance(name, (int, long)) and name or None
for node in dom:
- if node.get('t-name'):
- name = str(node.get("t-name"))
- self.add_template(qwebcontext, name, node)
- if res_id and node.tag == "t":
- self.add_template(qwebcontext, res_id, node)
- res_id = None
-
- def get_template(self, name, qwebcontext):
- """ Tries to fetch the template ``name``, either gets it from the
- context's template cache or loads one with the context's loader (if
- any).
-
- :raises QWebTemplateNotFound: if the template can not be found or loaded
- """
- origin_template = qwebcontext.get('__caller__') or qwebcontext['__stack__'][0]
- if qwebcontext.loader and name not in qwebcontext.templates:
- try:
- xml_doc = qwebcontext.loader(name)
- except ValueError:
- raise_qweb_exception(QWebTemplateNotFound, message="Loader could not find template %r" % name, template=origin_template)
- self.load_document(xml_doc, isinstance(name, (int, long)) and name or None, qwebcontext=qwebcontext)
-
- if name in qwebcontext.templates:
- return qwebcontext.templates[name]
+ if node.get('t-name') or (res_id and node.tag == "t"):
+ return node
raise QWebTemplateNotFound("Template %r not found" % name, template=origin_template)