From 1e6339ca5c49e5bcd90a1dd0b2e3f3b42fdb50f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 22 Feb 2019 14:58:43 +0100 Subject: [PATCH] bad POC for replace ugly image --- addons/web/controllers/main.py | 9 +++------ addons/web/static/src/js/boot.js | 18 ++++++++++++++++++ addons/web_editor/models/ir_ui_view.py | 9 +++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 3043d81e6183b..3c9a37ef9f8d1 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1057,17 +1057,14 @@ def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas if suffix in ('small', 'medium', 'large', 'big'): content = getattr(odoo.tools, 'image_resize_image_%s' % suffix)(content) + # if int(kw.get('img_optimize', 0)): + # width = 120 + # height = 0 content = limited_image_resize( content, width=width, height=height, crop=crop, upper_limit=upper_limit, avoid_if_small=avoid_if_small) image_base64 = base64.b64decode(content) - quality = int(kw.get('quality', 80)) - - # if request and 'image/webp' in request.httprequest.headers.get('Accept'): - # image_base64 = odoo.tools.image.image_save_for_web_webp(image_base64=image_base64, quality=quality) - # headers = self.force_contenttype(headers, contenttype='image/webp') - headers.append(('Content-Length', len(image_base64))) response = request.make_response(image_base64, headers) response.status_code = status diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 994b945b1d322..5077d630fae6d 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -290,4 +290,22 @@ }; $(log_when_loaded); + // function optimizeImages() { + // $('img.o_we_custom_image[src*="img_optimize=1"]').each(function () { + // var $img = $(this); + // setTimeout(function () { + // var url = $img.attr('src').replace('img_optimize=1', 'img_optimize=0'); + // var $downloadingImage = $(""); + // $downloadingImage.load(function () { + // $img.attr('src', url); + // }); + // $downloadingImage.attr("src", url); + // }, 2000); + // }); + // } + // // TODO SEB this won't work for newly added elements... + // $(document).ready(function () { + // optimizeImages(); + // }); + })(); diff --git a/addons/web_editor/models/ir_ui_view.py b/addons/web_editor/models/ir_ui_view.py index e281d9f9eccc9..1fd83e9b18682 100644 --- a/addons/web_editor/models/ir_ui_view.py +++ b/addons/web_editor/models/ir_ui_view.py @@ -4,6 +4,7 @@ import copy import logging from lxml import etree, html +from werkzeug import urls from odoo.exceptions import AccessError from odoo import api, fields, models @@ -172,6 +173,14 @@ def save(self, value, xpath=None): arch_section = html.fromstring( value, parser=html.HTMLParser(encoding='utf-8')) + # for img in arch_section.xpath(".//img[hasclass('o_we_custom_image')]"): + # url = img.get('src', '') + # url = urls.url_parse(url) + # url_params = url.decode_query() + # url_params.update([("img_optimize", 1)]) + # url = url.replace(query=urls.url_encode(url_params)).to_url() + # img.set('src', url) + if xpath is None: # value is an embedded field on its own, not a view section self.save_embedded_field(arch_section)