[ADD] cr, uid, context to qweb.render & qweb rendering context
bzr revid: xmo@openerp.com-20131018144546-p693x1iur5gm98ez
This commit is contained in:
@@ -58,10 +58,14 @@ class QWebException(Exception):
|
||||
#SAFE = ["_name"]
|
||||
|
||||
class QWebContext(dict):
|
||||
def __init__(self, data, undefined_handler=None, loader=None, templates=None):
|
||||
def __init__(self, cr, uid, data, undefined_handler=None, loader=None,
|
||||
templates=None, context=None):
|
||||
self.cr = cr
|
||||
self.uid = uid
|
||||
self.loader = loader
|
||||
self.undefined_handler = undefined_handler
|
||||
self.templates = templates or {}
|
||||
self.context = context
|
||||
dic = BUILTINS.copy()
|
||||
dic.update(data)
|
||||
super(QWebContext, self).__init__(dic)
|
||||
@@ -97,10 +101,11 @@ class QWebContext(dict):
|
||||
return eval(expr, None, self)
|
||||
|
||||
def copy(self):
|
||||
return QWebContext(dict.copy(self),
|
||||
return QWebContext(self.cr, self.uid, dict.copy(self),
|
||||
undefined_handler=self.undefined_handler,
|
||||
loader=self.loader,
|
||||
templates=self.templates)
|
||||
templates=self.templates,
|
||||
context=self.context)
|
||||
|
||||
def __copy__(self):
|
||||
return self.copy()
|
||||
@@ -235,11 +240,13 @@ class QWeb(orm.AbstractModel):
|
||||
else:
|
||||
return 0
|
||||
|
||||
def render(self, tname, v=None, out=None, loader=None, undefined_handler=None):
|
||||
def render(self, cr, uid, tname, v=None, loader=None,
|
||||
undefined_handler=None, context=None):
|
||||
if v is None:
|
||||
v = {}
|
||||
if not isinstance(v, QWebContext):
|
||||
v = QWebContext(v, undefined_handler=undefined_handler, loader=loader)
|
||||
v = QWebContext(cr, uid, v, undefined_handler=undefined_handler,
|
||||
loader=loader, context=context)
|
||||
v['__template__'] = tname
|
||||
stack = v.get('__stack__', [])
|
||||
if stack:
|
||||
@@ -448,8 +455,8 @@ class QWeb(orm.AbstractModel):
|
||||
|
||||
converter = self.get_converter_for(field_type)
|
||||
|
||||
return converter.to_html(record._cr, record._uid, field_name, record, options,
|
||||
e, t_att, g_att, v)
|
||||
return converter.to_html(v.cr, v.uid, field_name, record, options,
|
||||
e, t_att, g_att, v, context=v.context)
|
||||
|
||||
def get_converter_for(self, field_type):
|
||||
return self.pool.get('ir.qweb.field.' + field_type,
|
||||
@@ -511,7 +518,7 @@ class FieldConverter(osv.AbstractModel):
|
||||
cr, uid, record[field_name], column, options=None)
|
||||
|
||||
def to_html(self, cr, uid, field_name, record, options,
|
||||
source_element, t_att, g_att, qweb_context):
|
||||
source_element, t_att, g_att, qweb_context, context=None):
|
||||
""" Converts a ``t-field`` to its HTML output. A ``t-field`` may be
|
||||
extended by a ``t-field-options``, which is a JSON-serialized mapping
|
||||
of configuration values.
|
||||
|
||||
@@ -786,8 +786,9 @@ class view(osv.osv):
|
||||
return self.read_template(cr, uid, name, context=context)
|
||||
|
||||
return self.pool[engine].render(
|
||||
id_or_xml_id, values,
|
||||
loader=loader, undefined_handler=lambda key, v: None)
|
||||
cr, uid, id_or_xml_id, values,
|
||||
loader=loader, undefined_handler=lambda key, v: None,
|
||||
context=context)
|
||||
|
||||
# maybe used to print the workflow ?
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class TestCurrencyExport(TestExport):
|
||||
self.cr, self.uid, 'value', obj, options,
|
||||
doc.createElement('span'),
|
||||
{'field': 'obj.value', 'field-options': json.dumps(options)},
|
||||
'', ir_qweb.QWebContext({'obj': obj, 'c2': dest, }))
|
||||
'', ir_qweb.QWebContext(self.cr, self.uid, {'obj': obj, 'c2': dest, }))
|
||||
return converted
|
||||
|
||||
def test_currency_post(self):
|
||||
|
||||
@@ -24,9 +24,10 @@ class TestQWebTField(common.TransactionCase):
|
||||
})
|
||||
root_company = Companies.browse(self.cr, self.uid, company_id)
|
||||
|
||||
result = self.engine.render_node(field, ir_qweb.QWebContext({
|
||||
'company': root_company,
|
||||
}))
|
||||
result = self.engine.render_node(field, ir_qweb.QWebContext(
|
||||
self.cr, self.uid, {
|
||||
'company': root_company,
|
||||
}))
|
||||
|
||||
self.assertEqual(
|
||||
result,
|
||||
@@ -47,9 +48,10 @@ class TestQWebTField(common.TransactionCase):
|
||||
})
|
||||
root_company = Companies.browse(self.cr, self.uid, company_id)
|
||||
|
||||
result = self.engine.render_node(field, ir_qweb.QWebContext({
|
||||
'company': root_company,
|
||||
}))
|
||||
result = self.engine.render_node(field, ir_qweb.QWebContext(
|
||||
self.cr, self.uid, {
|
||||
'company': root_company,
|
||||
}))
|
||||
self.assertEqual(
|
||||
result,
|
||||
'<span data-oe-model="res.company" data-oe-id="%d" '
|
||||
@@ -65,7 +67,8 @@ class TestQWebTField(common.TransactionCase):
|
||||
with self.assertRaisesRegexp(
|
||||
AssertionError,
|
||||
r'^RTE widgets do not work correctly'):
|
||||
self.engine.render_node(field, ir_qweb.QWebContext({'company': None}))
|
||||
self.engine.render_node(field, ir_qweb.QWebContext(
|
||||
self.cr, self.uid, {'company': None}))
|
||||
|
||||
def test_reject_t_tag(self):
|
||||
field = document.createElement('t')
|
||||
@@ -74,4 +77,5 @@ class TestQWebTField(common.TransactionCase):
|
||||
with self.assertRaisesRegexp(
|
||||
AssertionError,
|
||||
r'^t-field can not be used on a t element'):
|
||||
self.engine.render_node(field, ir_qweb.QWebContext({'company': None}))
|
||||
self.engine.render_node(field, ir_qweb.QWebContext(
|
||||
self.cr, self.uid, {'company': None}))
|
||||
|
||||
Reference in New Issue
Block a user