[FIX] base, web: cleanup following previous commit
Removes the support for an asset bundle node returning content instead of an url, this was only usefull for css error. Part-of: odoo/odoo#131353
This commit is contained in:
@@ -144,7 +144,6 @@ class WebClient(http.Controller):
|
||||
data = [{
|
||||
"type": tag,
|
||||
"src": attrs.get("src") or attrs.get("data-src") or attrs.get('href'),
|
||||
"content": content,
|
||||
} for tag, attrs, content in files]
|
||||
} for tag, attrs in files]
|
||||
|
||||
return request.make_json_response(data)
|
||||
|
||||
@@ -104,7 +104,7 @@ assets.getBundle = memoize(async function getBundle(bundleName) {
|
||||
const json = await response.json();
|
||||
const assets = {
|
||||
cssLibs: [],
|
||||
cssContents: [],
|
||||
cssContents: [], //todo cleanup
|
||||
jsLibs: [],
|
||||
jsContents: [],
|
||||
};
|
||||
|
||||
@@ -77,9 +77,9 @@ class AssetsBundle(object):
|
||||
self._checksum_cache = {}
|
||||
self.is_debug_assets = debug_assets
|
||||
self.external_assets = [
|
||||
node
|
||||
for node in external_assets
|
||||
if (css and node[0].rpartition('.')[2] in STYLE_EXTENSIONS) or (js and node[0].rpartition('.')[2] in SCRIPT_EXTENSIONS)
|
||||
url
|
||||
for url in external_assets
|
||||
if (css and url.rpartition('.')[2] in STYLE_EXTENSIONS) or (js and url.rpartition('.')[2] in SCRIPT_EXTENSIONS)
|
||||
]
|
||||
|
||||
# asset-wide html "media" attribute
|
||||
@@ -117,16 +117,16 @@ class AssetsBundle(object):
|
||||
if self.has_css and self.stylesheets:
|
||||
css_attachment = self.css(is_minified=not self.is_debug_assets)
|
||||
if self.is_debug_assets:
|
||||
response.append((self.get_debug_asset_url(extra=self.extra('css'), name=css_attachment.name, extension=''), None))
|
||||
response.append(self.get_debug_asset_url(extra=self.extra('css'), name=css_attachment.name, extension=''))
|
||||
else:
|
||||
response.append((css_attachment.url, None))
|
||||
response.append(css_attachment.url)
|
||||
|
||||
if self.has_js and self.javascripts:
|
||||
js_attachment = self.js(is_minified=not self.is_debug_assets)
|
||||
if self.is_debug_assets:
|
||||
response.append((self.get_debug_asset_url(extra=self.extra('js'), name=js_attachment.name, extension=''), None))
|
||||
response.append(self.get_debug_asset_url(extra=self.extra('js'), name=js_attachment.name, extension=''))
|
||||
else:
|
||||
response.append((js_attachment.url, None))
|
||||
response.append(js_attachment.url)
|
||||
|
||||
return self.external_assets + response
|
||||
|
||||
|
||||
@@ -2203,7 +2203,7 @@ class IrQWeb(models.AbstractModel):
|
||||
""".strip(), level))
|
||||
|
||||
code.append(indent_code("""
|
||||
for index, (tagName, asset_attrs, content) in enumerate(t_call_assets_nodes):
|
||||
for index, (tagName, asset_attrs) in enumerate(t_call_assets_nodes):
|
||||
if index:
|
||||
yield '\\n '
|
||||
yield '<'
|
||||
@@ -2214,12 +2214,10 @@ class IrQWeb(models.AbstractModel):
|
||||
if value or isinstance(value, str):
|
||||
yield f' {escape(str(name))}="{escape(str(value))}"'
|
||||
|
||||
if not content and tagName in VOID_ELEMENTS:
|
||||
if tagName in VOID_ELEMENTS:
|
||||
yield '/>'
|
||||
else:
|
||||
yield '>'
|
||||
if content:
|
||||
yield content
|
||||
yield '</'
|
||||
yield tagName
|
||||
yield '>'
|
||||
@@ -2544,7 +2542,7 @@ class IrQWeb(models.AbstractModel):
|
||||
'last_modified': last_modified,
|
||||
})
|
||||
else:
|
||||
external_asset.append((path, None))
|
||||
external_asset.append(path)
|
||||
return (files, external_asset)
|
||||
|
||||
def _get_asset_bundle(self, bundle_name, css=True, js=True, debug_assets=False, rtl=False, assets_params=None):
|
||||
@@ -2556,8 +2554,7 @@ class IrQWeb(models.AbstractModel):
|
||||
def _links_to_nodes(self, paths, defer_load=False, lazy_load=False, media=None):
|
||||
return [self._link_to_node(path, defer_load=defer_load, lazy_load=lazy_load, media=media) for path in paths]
|
||||
|
||||
def _link_to_node(self, descriptor, defer_load=False, lazy_load=False, media=None):
|
||||
path, js_content = descriptor # small hack to manage css compilation error, to transform into a full css solution or saved js error
|
||||
def _link_to_node(self, path, defer_load=False, lazy_load=False, media=None):
|
||||
ext = path.rsplit('.', maxsplit=1)[-1] if path else 'js'
|
||||
is_js = ext in SCRIPT_EXTENSIONS
|
||||
is_xml = ext in TEMPLATE_EXTENSIONS
|
||||
@@ -2582,10 +2579,7 @@ class IrQWeb(models.AbstractModel):
|
||||
if is_asset_bundle:
|
||||
attributes['onerror'] = "__odooAssetError=1"
|
||||
|
||||
if js_content:
|
||||
attributes['charset'] = 'utf-8'
|
||||
|
||||
return ('script', attributes, js_content)
|
||||
return ('script', attributes)
|
||||
|
||||
|
||||
if is_css:
|
||||
@@ -2595,7 +2589,7 @@ class IrQWeb(models.AbstractModel):
|
||||
'href': path,
|
||||
'media': media,
|
||||
}
|
||||
return ('link', attributes, None)
|
||||
return ('link', attributes)
|
||||
|
||||
if is_xml:
|
||||
attributes = {
|
||||
@@ -2604,7 +2598,7 @@ class IrQWeb(models.AbstractModel):
|
||||
'rel': 'prefetch',
|
||||
'data-src': path,
|
||||
}
|
||||
return ('script', attributes, None)
|
||||
return ('script', attributes)
|
||||
|
||||
def _generate_asset_links(self, bundle, css=True, js=True, debug_assets=False, assets_params=None, rtl=False):
|
||||
asset_bundle = self._get_asset_bundle(bundle, css=css, js=js, debug_assets=debug_assets, rtl=rtl, assets_params=assets_params)
|
||||
|
||||
@@ -299,7 +299,7 @@ class TestJavascriptAssetsBundle(FileTouchable):
|
||||
debug_bundle = self._get_asset(self.jsbundle_name)
|
||||
content = debug_bundle.get_links()
|
||||
# there should be a minified file
|
||||
self.assertIn('test_assetsbundle.bundle1.min.js', content[0][0])
|
||||
self.assertIn('test_assetsbundle.bundle1.min.js', content[0])
|
||||
|
||||
# there should be one minified assets created in normal mode
|
||||
self.assertEqual(len(self._any_ira_for_bundle('min.js')), 1,
|
||||
@@ -316,7 +316,7 @@ class TestJavascriptAssetsBundle(FileTouchable):
|
||||
debug_bundle = self._get_asset(self.jsbundle_name, debug_assets=True)
|
||||
content = debug_bundle.get_links()
|
||||
# there should be a minified file
|
||||
self.assertIn('test_assetsbundle.bundle1.js', content[0][0], "there should be one non-minified assets created in debug assets mode")
|
||||
self.assertIn('test_assetsbundle.bundle1.js', content[0], "there should be one non-minified assets created in debug assets mode")
|
||||
|
||||
# there shouldn't be any minified assets created in debug mode
|
||||
self.assertEqual(len(self._any_ira_for_bundle('min.js')), 0,
|
||||
@@ -392,7 +392,7 @@ class TestJavascriptAssetsBundle(FileTouchable):
|
||||
debug_bundle = self._get_asset(self.cssbundle_name, debug_assets=True)
|
||||
content = debug_bundle.get_links()
|
||||
# there should be a minified file
|
||||
self.assertEqual(content[0][0], '/web/assets/debug/ltr/test_assetsbundle.bundle2.css')
|
||||
self.assertEqual(content[0], '/web/assets/debug/ltr/test_assetsbundle.bundle2.css')
|
||||
|
||||
# there should be one css asset created in debug mode
|
||||
self.assertEqual(len(self._any_ira_for_bundle('css')), 1,
|
||||
@@ -414,7 +414,7 @@ class TestJavascriptAssetsBundle(FileTouchable):
|
||||
|
||||
# the ir.attachment records should be deduplicated in the bundle's content
|
||||
content = bundle0.get_links()
|
||||
self.assertIn('test_assetsbundle.bundle2.min.css', content[0][0])
|
||||
self.assertIn('test_assetsbundle.bundle2.min.css', content[0])
|
||||
|
||||
# Language direction specific tests
|
||||
|
||||
@@ -596,7 +596,7 @@ class TestJavascriptAssetsBundle(FileTouchable):
|
||||
content = debug_bundle.get_links()
|
||||
|
||||
# there should be an css assets bundle in /debug/rtl if user's lang direction is rtl and debug=assets
|
||||
self.assertEqual(f'/web/assets/debug/rtl/{self.cssbundle_name}.css', content[0][0],
|
||||
self.assertEqual(f'/web/assets/debug/rtl/{self.cssbundle_name}.css', content[0],
|
||||
"there should be an css assets bundle in /debug/rtl if user's lang direction is rtl and debug=assets")
|
||||
|
||||
# there should be an css assets bundle created in /rtl if user's lang direction is rtl and debug=assets
|
||||
|
||||
Reference in New Issue
Block a user