[IMP] qweb: typo and adapt
This commit is contained in:
@@ -6,4 +6,4 @@ from . import assetsbundle
|
||||
|
||||
from .assetsbundle import AssetsBundle
|
||||
from .qweb import unicodifier, QWebException
|
||||
from .ir_qweb import ir_QWeb, QWeb
|
||||
from .ir_qweb import IrQWeb, QWeb
|
||||
|
||||
@@ -19,7 +19,7 @@ import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ir_QWeb(models.AbstractModel, QWeb):
|
||||
class IrQWeb(models.AbstractModel, QWeb):
|
||||
""" Base QWeb rendering engine
|
||||
* to customize ``t-field`` rendering, subclass ``ir.qweb.field`` and
|
||||
create new models called :samp:`ir.qweb.field.{widget}`
|
||||
@@ -41,17 +41,15 @@ class ir_QWeb(models.AbstractModel, QWeb):
|
||||
if method.startswith('render_'):
|
||||
_logger.warning("Unused method '%s' is found in ir.qweb." % method)
|
||||
|
||||
body = []
|
||||
context = dict(self.env.context, dev_mode='qweb' in tools.config['dev_mode'])
|
||||
context.update(options)
|
||||
|
||||
self.compile(id_or_xml_id, context)(self, body.append, values or {})
|
||||
return u''.join(body)
|
||||
return super(IrQWeb, self).render(id_or_xml_id, values=values, **context)
|
||||
|
||||
def default_values(self):
|
||||
""" attributes add to the values for each computed template
|
||||
"""
|
||||
default = super(ir_QWeb, self).default_values()
|
||||
default = super(IrQWeb, self).default_values()
|
||||
default.update(request=request, cache_assets=round(time()/180))
|
||||
return default
|
||||
|
||||
@@ -66,7 +64,7 @@ class ir_QWeb(models.AbstractModel, QWeb):
|
||||
tools.ormcache('id_or_xml_id', 'tuple(map(options.get, self._get_template_cache_keys()))'),
|
||||
)
|
||||
def compile(self, id_or_xml_id, options):
|
||||
return super(ir_QWeb, self).compile(id_or_xml_id, options=options)
|
||||
return super(IrQWeb, self).compile(id_or_xml_id, options=options)
|
||||
|
||||
def load(self, name, options):
|
||||
lang = options.get('lang', 'en_US')
|
||||
@@ -89,7 +87,7 @@ class ir_QWeb(models.AbstractModel, QWeb):
|
||||
# order
|
||||
|
||||
def _directives_eval_order(self):
|
||||
directives = super(ir_QWeb, self)._directives_eval_order()
|
||||
directives = super(IrQWeb, self)._directives_eval_order()
|
||||
directives.insert(directives.index('call'), 'lang')
|
||||
directives.insert(directives.index('field'), 'call-assets')
|
||||
return directives
|
||||
@@ -97,7 +95,11 @@ class ir_QWeb(models.AbstractModel, QWeb):
|
||||
# compile directives
|
||||
|
||||
def _compile_directive_lang(self, el, options):
|
||||
el.set('t-call-options', '{"lang": %s}' % el.attrib.pop('t-lang', 'en_US'))
|
||||
lang = el.attrib.pop('t-lang', 'en_US')
|
||||
if el.get('t-call-options'):
|
||||
el.set('t-call-options', el.get('t-call-options')[0:-1] + u', "lang": %s}' % lang)
|
||||
else:
|
||||
el.set('t-call-options', u'{"lang": %s}' % lang)
|
||||
return self._compile_node(el, options)
|
||||
|
||||
def _compile_directive_call_assets(self, el, options):
|
||||
|
||||
@@ -245,7 +245,7 @@ class QWeb(object):
|
||||
'values' is used to evaluate template values
|
||||
"""
|
||||
body = []
|
||||
self.compile(template, options)(self, body.append, values)
|
||||
self.compile(template, options)(self, body.append, values or {})
|
||||
return u''.join(body)
|
||||
|
||||
def compile(self, template, options):
|
||||
@@ -395,7 +395,7 @@ class QWeb(object):
|
||||
def format(self, value, formating, *args, **kwargs):
|
||||
format = getattr(self, '_format_func_%s' % formating, None)
|
||||
if not format:
|
||||
raise "Unknown formating '%s'" % (formating,)
|
||||
raise "Unknown format '%s'" % (formating,)
|
||||
return format(value, *args, **kwargs)
|
||||
|
||||
# compute helpers
|
||||
@@ -570,7 +570,7 @@ class QWeb(object):
|
||||
)
|
||||
|
||||
def _append(self, item):
|
||||
assert isinstance(item, ast.expr) or isinstance(item, ast.Expr)
|
||||
assert isinstance(item, ast.expr)
|
||||
return ast.Expr(ast.Call(
|
||||
func=ast.Name(id='append', ctx=ast.Load()),
|
||||
args=[item], keywords=[],
|
||||
|
||||
@@ -303,7 +303,7 @@ actual arch.
|
||||
def _check_groups(self):
|
||||
for view in self:
|
||||
if view.type == 'qweb' and view.groups_id:
|
||||
raise ValidationError(_("Qweb view can not have 'Groups' define on the record. Use 'groups' atttributes inside the view definition"))
|
||||
raise ValidationError(_("Qweb view cannot have 'Groups' define on the record. Use 'groups' atttributes inside the view definition"))
|
||||
|
||||
_sql_constraints = [
|
||||
('inheritance_mode',
|
||||
|
||||
@@ -11,7 +11,7 @@ from lxml import etree
|
||||
|
||||
from odoo.modules import get_module_resource
|
||||
from odoo.tests.common import TransactionCase
|
||||
from openerp.addons.base.ir.ir_qweb import QWebException
|
||||
from odoo.addons.base.ir.ir_qweb import QWebException
|
||||
|
||||
|
||||
class TestQWebTField(TransactionCase):
|
||||
|
||||
Reference in New Issue
Block a user