From d445f46806eb64064c77824e5ee564df0374f4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 21 May 2019 10:34:40 +0000 Subject: [PATCH] [FIX] *: convert image route size param to int and use named param MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * = tools, base, web, website_profile, website_slides Before this commit it was impossible to pass those parameters in the URL because they were received as string but expected as int. The opportunity is also taken to properly use named parameters when calling `image_process`. closes odoo/odoo#33506 Signed-off-by: Jérémy Kersten (jke) --- addons/web/controllers/main.py | 2 +- addons/website_profile/controllers/main.py | 2 +- addons/website_slides/controllers/main.py | 2 +- odoo/addons/base/models/res_company.py | 2 +- odoo/addons/base/tests/test_ir_http.py | 2 +- odoo/tools/image.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index b6bca60fedd..3053ad286ee 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1049,7 +1049,7 @@ class Binary(http.Controller): if not (width or height): width, height = odoo.tools.image_guess_size_from_field_name(field) - image_base64 = image_process(image_base64, (width, height), crop=crop) + image_base64 = image_process(image_base64, size=(int(width), int(height)), crop=crop) content = base64.b64decode(image_base64) headers = http.set_safe_image_headers(headers, content) diff --git a/addons/website_profile/controllers/main.py b/addons/website_profile/controllers/main.py index 5d379643e5d..e46e72b2cfb 100644 --- a/addons/website_profile/controllers/main.py +++ b/addons/website_profile/controllers/main.py @@ -95,7 +95,7 @@ class WebsiteProfile(http.Controller): if not (width or height): width, height = tools.image_guess_size_from_field_name(field) - image_base64 = tools.image_process(image_base64, (width, height), crop=crop) + image_base64 = tools.image_process(image_base64, size=(int(width), int(height)), crop=crop) content = base64.b64decode(image_base64) headers = http.set_safe_image_headers(headers, content) diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py index a4682a04313..5bff0ef6adb 100644 --- a/addons/website_slides/controllers/main.py +++ b/addons/website_slides/controllers/main.py @@ -544,7 +544,7 @@ class WebsiteSlides(WebsiteProfile): if not (width or height): width, height = tools.image_guess_size_from_field_name(field) - image_base64 = tools.image_process(image_base64, (width, height), crop=crop) + image_base64 = tools.image_process(image_base64, size=(int(width), int(height)), crop=crop) content = base64.b64decode(image_base64) headers = http.set_safe_image_headers(headers, content) diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index 9dfbf9bdced..a577b6def12 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -155,7 +155,7 @@ class Company(models.Model): @api.depends('partner_id', 'partner_id.image') def _compute_logo_web(self): for company in self: - company.logo_web = tools.image_process(company.partner_id.image, (180, None)) + company.logo_web = tools.image_process(company.partner_id.image, size=(180, 0)) @api.onchange('state_id') def _onchange_state(self): diff --git a/odoo/addons/base/tests/test_ir_http.py b/odoo/addons/base/tests/test_ir_http.py index 9f034c9d896..09efa81bd51 100644 --- a/odoo/addons/base/tests/test_ir_http.py +++ b/odoo/addons/base/tests/test_ir_http.py @@ -64,7 +64,7 @@ class test_ir_http_mimetype(common.TransactionCase): 'type': 'binary', }) - resized = odoo.tools.image_process(prop.value_binary, odoo.tools.IMAGE_SMALL_SIZE) + resized = odoo.tools.image_process(prop.value_binary, size=odoo.tools.IMAGE_SMALL_SIZE) # Simul computed field which resize and that is not attachement=True (E.G. on product) prop.write({'value_binary': resized}) status, headers, content = self.env['ir.http'].binary_content( diff --git a/odoo/tools/image.py b/odoo/tools/image.py index 7bb77191e87..c7c58a11d03 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -387,5 +387,5 @@ if __name__=="__main__": assert len(sys.argv)==3, 'Usage to Test: image.py SRC.png DEST.png' img = base64.b64encode(open(sys.argv[1],'rb').read()) - new = image_process(img, (128, 100)) + new = image_process(img, size=(128, 100)) open(sys.argv[2], 'wb').write(base64.b64decode(new))