From ae3997b8bf7e539f91a64870ced76868550bae12 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Thu, 11 Oct 2018 17:02:47 +0000 Subject: [PATCH] [FIX] web: guess resize placeholder Before this commit, if you ask for a small image, you was waiting a picture of 64x64 but in case this image was not found, a placeholder with an other size was returned. Now, we try to guess the asked size, and return a resized placeholder. This bug appear since we change the default placeholder picture with a big one This will fix several issue and avoid to hard code size everywhere in the code Eg: commit 92f837c and commit https://github.com/odoo/odoo/commit/154fc7d9dd550d35b7266af024e54c20e18938fc#diff-9af1af2039d16d6b544d481b4ee1ed7cR144 closes odoo/odoo#27695 --- addons/web/controllers/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 35332e4fe79..cc162d57ded 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1073,7 +1073,12 @@ class Binary(http.Controller): if content: image_base64 = base64.b64decode(content) else: - image_base64 = self.placeholder(image='placeholder.png') # could return (contenttype, content) in master + suffix = field.split('_')[-1] + if suffix in ('small', 'medium', 'big'): + encoded_placeholder = base64.b64encode(self.placeholder(image='placeholder.png')) + image_base64 = base64.b64decode(getattr(odoo.tools, 'image_resize_image_%s' % suffix)(encoded_placeholder)) + else: + image_base64 = self.placeholder(image='placeholder.png') # could return (contenttype, content) in master headers = self.force_contenttype(headers, contenttype='image/png') headers.append(('Content-Length', len(image_base64)))