Skip to content

Commit

Permalink
[FIX] *: convert image route size param to int and use named param
Browse files Browse the repository at this point in the history
* = 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#33506

Signed-off-by: Jérémy Kersten (jke) <[email protected]>
  • Loading branch information
seb-odoo committed May 21, 2019
1 parent 9613483 commit d445f46
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion addons/web/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def _content_image(self, xmlid=None, model='ir.attachment', id=None, field='data
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)
Expand Down
2 changes: 1 addition & 1 deletion addons/website_profile/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_user_profile_avatar(self, user_id, field='image_large', width=0, height=
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)
Expand Down
2 changes: 1 addition & 1 deletion addons/website_slides/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def slide_get_image(self, slide_id, field='image_medium', width=0, height=0, cro
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)
Expand Down
2 changes: 1 addition & 1 deletion odoo/addons/base/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _inverse_country(self):
@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):
Expand Down
2 changes: 1 addition & 1 deletion odoo/addons/base/tests/test_ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_ir_http_mimetype_computed_field(self):
'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(
Expand Down
2 changes: 1 addition & 1 deletion odoo/tools/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,5 @@ def image_data_uri(base64_source):
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))

0 comments on commit d445f46

Please sign in to comment.