[REM] Removed QWebContext.templates cache

Now rely solely on ir.ui.view#read_template()'s orm cache
This commit is contained in:
Fabien Meghazi
2014-11-07 16:25:17 +01:00
parent 4127468829
commit 30e21de532
+11 -39
View File
@@ -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 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)
def load_document(self, document, res_id, qwebcontext):
"""
Loads an XML document and installs any contained template in the engine
: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)