[ADD] web: add /web/assets for assets bundle

Part of PR 63177
This commit is contained in:
Francois (fge)
2021-02-15 10:55:00 +01:00
parent d29666c04c
commit 402740f73e
5 changed files with 23 additions and 8 deletions
+17 -3
View File
@@ -1434,15 +1434,16 @@ class Binary(http.Controller):
'/web/content/<string:xmlid>/<string:filename>',
'/web/content/<int:id>',
'/web/content/<int:id>/<string:filename>',
'/web/content/<int:id>-<string:unique>',
'/web/content/<int:id>-<string:unique>/<string:filename>',
'/web/content/<int:id>-<string:unique>/<path:extra>/<string:filename>',
'/web/content/<string:model>/<int:id>/<string:field>',
'/web/content/<string:model>/<int:id>/<string:field>/<string:filename>'], type='http', auth="public")
def content_common(self, xmlid=None, model='ir.attachment', id=None, field='datas',
filename=None, filename_field='name', unique=None, mimetype=None,
download=None, data=None, token=None, access_token=None, **kw):
return self._get_content_common(xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename,
filename_field=filename_field, download=download, mimetype=mimetype, access_token=access_token, token=token)
def _get_content_common(self, xmlid, model, id, field, unique, filename, filename_field, download, mimetype, access_token, token):
status, headers, content = request.env['ir.http'].binary_content(
xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename,
filename_field=filename_field, download=download, mimetype=mimetype, access_token=access_token)
@@ -1457,6 +1458,19 @@ class Binary(http.Controller):
response.set_cookie('fileToken', token)
return response
@http.route(['/web/assets/debug/<string:filename>',
'/web/assets/debug/<path:extra>/<string:filename>',
'/web/assets/<int:id>/<string:filename>',
'/web/assets/<int:id>-<string:unique>/<string:filename>',
'/web/assets/<int:id>-<string:unique>/<path:extra>/<string:filename>'], type='http', auth="public")
def content_assets(self, id=None, filename=None, unique=None, extra=None, **kw):
id = id or request.env['ir.attachment'].sudo().search_read(
[('url', '=like', f'/web/assets/%/{extra}/{filename}' if extra else f'/web/assets/%/{filename}')],
fields=['id'], limit=1)[0]['id']
return self._get_content_common(xmlid=None, model='ir.attachment', id=id, field='datas', unique=unique, filename=filename,
filename_field='name', download=None, mimetype=None, access_token=None, token=None)
@http.route(['/web/partner_image',
'/web/partner_image/<int:rec_id>',
'/web/partner_image/<int:rec_id>/<string:field>',
+1
View File
@@ -30,6 +30,7 @@ DEFAULT_CDN_FILTERS = [
"^/web/(css|js)/",
"^/web/image",
"^/web/content",
"^/web/assets",
# retrocompatibility
"^/website/image/",
]
+3 -3
View File
@@ -115,8 +115,8 @@ class TestWebsitePerformance(UtilPerf):
self.assertEqual(self._get_url_hot_query(self.page.url), 11)
def test_50_perf_sql_web_content(self):
# assets route /web/content/..
def test_50_perf_sql_web_assets(self):
# assets route /web/assets/..
self.url_open('/') # create assets attachments
assets_url = self.env['ir.attachment'].search([('url', '=like', '/web/content/%/web.assets_common%.js')], limit=1).url
assets_url = self.env['ir.attachment'].search([('url', '=like', '/web/assets/%/web.assets_common%.js')], limit=1).url
self.assertEqual(self._get_url_hot_query(assets_url), 2)
+1 -1
View File
@@ -41,7 +41,7 @@ class TestQweb(TransactionCaseWithUserDemo):
html = html.strip().decode('utf8')
html = re.sub(r'\?unique=[^"]+', '', html).encode('utf8')
attachments = demo_env['ir.attachment'].search([('url', '=like', '/web/content/%-%/website.test_bundle.%')])
attachments = demo_env['ir.attachment'].search([('url', '=like', '/web/assets/%-%/website.test_bundle.%')])
self.assertEqual(len(attachments), 2)
format_data = {
+1 -1
View File
@@ -311,7 +311,7 @@ class IrQWeb(models.AbstractModel, QWeb):
IrQweb = self.env['ir.qweb'].with_context(options)
def can_aggregate(url):
return not urls.url_parse(url).scheme and not urls.url_parse(url).netloc and not url.startswith('/web/content')
return not urls.url_parse(url).scheme and not urls.url_parse(url).netloc and not url.startswith('/web/assets')
# TODO: This helper can be used by any template that wants to embedd the backend.
# It is currently necessary because the ir.ui.view bundle inheritance does not