[REV] fix ir.qweb#render() return type
This commit reverts the API change introduced in b3302398bc
that changes `ir.qweb#render()` to return a unicode string instead of a utf8
encoded bytestring.
Returning a unicode string is undoubtedly cleaner and a step in the direction
of python 3 but still is an API change that can break third party modules.
Let's wait the migration to python 3 before breaking other people's toys.
This commit is contained in:
@@ -140,7 +140,7 @@ class Report(osv.Model):
|
||||
'doc_model': report.model,
|
||||
'docs': docs,
|
||||
}
|
||||
return self.render(cr, uid, [], report.report_name, docargs, context=context).encode('utf-8')
|
||||
return self.render(cr, uid, [], report.report_name, docargs, context=context)
|
||||
|
||||
@api.v8
|
||||
def get_html(self, records, report_name, data=None):
|
||||
@@ -183,6 +183,8 @@ class Report(osv.Model):
|
||||
if isinstance(cr, TestCursor):
|
||||
return html
|
||||
|
||||
html = html.decode('utf-8') # Ensure the current document is utf-8 encoded.
|
||||
|
||||
# Get the ir.actions.report.xml record we are working on.
|
||||
report = self._get_report_from_name(cr, uid, report_name)
|
||||
# Check if we have to save the report or if we have to get one from the db.
|
||||
|
||||
@@ -244,7 +244,7 @@ class QWeb(object):
|
||||
"""
|
||||
body = []
|
||||
self.compile(template, options)(self, body.append, values or {})
|
||||
return u''.join(body)
|
||||
return u''.join(body).encode('utf8')
|
||||
|
||||
def compile(self, template, options):
|
||||
""" Compile the given template into a rendering function::
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestQWebTField(TransactionCase):
|
||||
field = etree.Element('span', {'t-field': u'company.name'})
|
||||
company = self.env['res.company'].create({'name': "My Test Company"})
|
||||
|
||||
result = self.engine.render(field, {'company': company}).encode('utf-8')
|
||||
result = self.engine.render(field, {'company': company})
|
||||
self.assertEqual(
|
||||
result,
|
||||
'<span data-oe-model="res.company" data-oe-id="%d" '
|
||||
@@ -41,7 +41,7 @@ class TestQWebTField(TransactionCase):
|
||||
s = u"Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!"
|
||||
company = self.env['res.company'].create({'name': s})
|
||||
|
||||
result = self.engine.render(field, {'company': company}).encode('utf-8')
|
||||
result = self.engine.render(field, {'company': company})
|
||||
self.assertEqual(
|
||||
result,
|
||||
'<span data-oe-model="res.company" data-oe-id="%d" '
|
||||
@@ -56,13 +56,13 @@ class TestQWebTField(TransactionCase):
|
||||
field = etree.Element('td', {'t-field': u'company.name'})
|
||||
|
||||
with self.assertRaisesRegexp(QWebException, r'^RTE widgets do not work correctly'):
|
||||
self.engine.render(field, {'company': None}).encode('utf-8')
|
||||
self.engine.render(field, {'company': None})
|
||||
|
||||
def test_reject_t_tag(self):
|
||||
field = etree.Element('t', {'t-field': u'company.name'})
|
||||
|
||||
with self.assertRaisesRegexp(QWebException, r'^t-field can not be used on a t element'):
|
||||
self.engine.render(field, {'company': None}).encode('utf-8')
|
||||
self.engine.render(field, {'company': None})
|
||||
|
||||
|
||||
from copy import deepcopy
|
||||
@@ -128,7 +128,7 @@ class TestQWeb(TransactionCase):
|
||||
|
||||
result = doc.find('result[@id="{}"]'.format(template)).text
|
||||
self.assertEqual(
|
||||
qweb.render(template, values=params, load=loader).strip().encode('utf-8'),
|
||||
qweb.render(template, values=params, load=loader).strip(),
|
||||
(result or u'').strip().encode('utf-8'),
|
||||
template
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user