summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2018-07-16 11:43:48 +0200
committerMartin Trigaux <mat@odoo.com>2018-07-17 13:25:33 +0200
commit5a57c29ff2ac0c6b75aaba963b094809b8e60d44 (patch)
tree916371904fcae231dd65f82f6632ab6a9453776b
parent5705e3e5d27b1ce815c182510f13baccfcf0b038 (diff)
[FIX] base: do not use async reserved keyword
In python 3.7, async is a reserved keyword. Using it in a method signature produces a syntax error. Replace by an argument async_load and catch the previous calls in a kw for backward compatibility. Log a warning on public methods. The **kw can be removed in v12 and officially deprecate the 'async' parameter. Fixes #25578 Closes #25783
-rw-r--r--odoo/addons/base/ir/ir_qweb/assetsbundle.py14
-rw-r--r--odoo/addons/base/ir/ir_qweb/ir_qweb.py16
2 files changed, 20 insertions, 10 deletions
diff --git a/odoo/addons/base/ir/ir_qweb/assetsbundle.py b/odoo/addons/base/ir/ir_qweb/assetsbundle.py
index aae2f179ab5..b0f2ef2786d 100644
--- a/odoo/addons/base/ir/ir_qweb/assetsbundle.py
+++ b/odoo/addons/base/ir/ir_qweb/assetsbundle.py
@@ -102,8 +102,11 @@ class AssetsBundle(object):
self.javascripts.append(JavascriptAsset(self, url=f['url'], filename=f['filename'], inline=f['content']))
# depreciated and will remove after v11
- def to_html(self, sep=None, css=True, js=True, debug=False, async=False, url_for=(lambda url: url)):
- nodes = self.to_node(css=css, js=js, debug=debug, async=async)
+ def to_html(self, sep=None, css=True, js=True, debug=False, async_load=False, url_for=(lambda url: url), **kw):
+ if 'async' in kw:
+ _logger.warning("Using deprecated argument 'async' in to_html call, use 'async_load' instead.")
+ async_load = kw['async']
+ nodes = self.to_node(css=css, js=js, debug=debug, async_load=async_load)
if sep is None:
sep = u'\n '
@@ -121,10 +124,13 @@ class AssetsBundle(object):
return sep + sep.join(response)
- def to_node(self, css=True, js=True, debug=False, async=False):
+ def to_node(self, css=True, js=True, debug=False, async_load=False, **kw):
"""
:returns [(tagName, attributes, content)] if the tag is auto close
"""
+ if 'async' in kw:
+ _logger.warning("Using deprecated argument 'async' in to_node call, use 'async_load' instead.")
+ async_load = kw['async']
response = []
if debug == 'assets':
if css and self.stylesheets:
@@ -157,7 +163,7 @@ class AssetsBundle(object):
response.append(JavascriptAsset(self, inline=self.dialog_message(msg)).to_node())
if js and self.javascripts:
attr = OrderedDict([
- ["async", "async" if async else None],
+ ["async", "async" if async_load else None],
["type", "text/javascript"],
["src", self.js().url],
])
diff --git a/odoo/addons/base/ir/ir_qweb/ir_qweb.py b/odoo/addons/base/ir/ir_qweb/ir_qweb.py
index 1c2f07185ae..7b612eb901e 100644
--- a/odoo/addons/base/ir/ir_qweb/ir_qweb.py
+++ b/odoo/addons/base/ir/ir_qweb/ir_qweb.py
@@ -278,24 +278,28 @@ class IrQWeb(models.AbstractModel, QWeb):
# compatibility to remove after v11 - DEPRECATED
@tools.conditional(
'xml' not in tools.config['dev_mode'],
- tools.ormcache_context('xmlid', 'options.get("lang", "en_US")', 'css', 'js', 'debug', 'async', keys=("website_id",)),
+ tools.ormcache_context('xmlid', 'options.get("lang", "en_US")', 'css', 'js', 'debug', 'kw.get("async")', 'async_load', keys=("website_id",)),
)
- def _get_asset(self, xmlid, options, css=True, js=True, debug=False, async=False, values=None):
+ def _get_asset(self, xmlid, options, css=True, js=True, debug=False, async_load=False, values=None, **kw):
+ if 'async' in kw:
+ async_load = kw['async']
files, remains = self._get_asset_content(xmlid, options)
asset = self.get_asset_bundle(xmlid, files, remains, env=self.env)
- return asset.to_html(css=css, js=js, debug=debug, async=async, url_for=(values or {}).get('url_for', lambda url: url))
+ return asset.to_html(css=css, js=js, debug=debug, async_load=async_load, url_for=(values or {}).get('url_for', lambda url: url))
@tools.conditional(
# in non-xml-debug mode we want assets to be cached forever, and the admin can force a cache clear
# by restarting the server after updating the source code (or using the "Clear server cache" in debug tools)
'xml' not in tools.config['dev_mode'],
- tools.ormcache_context('xmlid', 'options.get("lang", "en_US")', 'css', 'js', 'debug', 'async', keys=("website_id",)),
+ tools.ormcache_context('xmlid', 'options.get("lang", "en_US")', 'css', 'js', 'debug', 'kw.get("async")', 'async_load', keys=("website_id",)),
)
- def _get_asset_nodes(self, xmlid, options, css=True, js=True, debug=False, async=False, values=None):
+ def _get_asset_nodes(self, xmlid, options, css=True, js=True, debug=False, async_load=False, values=None, **kw):
+ if 'async' in kw:
+ async_load = kw['async']
files, remains = self._get_asset_content(xmlid, options)
asset = self.get_asset_bundle(xmlid, files, env=self.env)
remains = [node for node in remains if (css and node[0] == 'link') or (js and node[0] != 'link')]
- return remains + asset.to_node(css=css, js=js, debug=debug, async=async)
+ return remains + asset.to_node(css=css, js=js, debug=debug, async_load=async_load)
@tools.ormcache_context('xmlid', 'options.get("lang", "en_US")', keys=("website_id",))
def _get_asset_content(self, xmlid, options):