[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
This commit is contained in:
Jeremy Kersten
2018-11-06 18:37:29 +01:00
committed by Christophe Simonis
parent eaa93d1bd4
commit ae3997b8bf
+6 -1
View File
@@ -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)))