Skip to content
Permalink
Browse files

[IMP] web,website_profile,website_slides: rename content and base64

There is a mix in the variable names: before this commit, what is called
`image_base64` is actually not base64 encoded, and what is called `content` is
actually base64 encoded.

The variables have been renamed to avoid further confusion.

PR: #31811
  • Loading branch information...
seb-odoo committed Mar 15, 2019
1 parent cb1a30d commit 138708285725dc4ce2a8e489eebbf2dc62c01e94
@@ -1041,28 +1041,27 @@ def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas
filename_field='datas_fname', unique=None, filename=None, mimetype=None,
download=None, width=0, height=0, crop=False, access_token=None, avoid_if_small=False,
upper_limit=False, **kw):
status, headers, content = request.env['ir.http'].binary_content(
status, headers, image_base64 = request.env['ir.http'].binary_content(
xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename,
filename_field=filename_field, download=download, mimetype=mimetype,
default_mimetype='image/png', access_token=access_token)

if status == 301 or (status != 200 and download):
return request.env['ir.http']._response_by_status(status, headers, content)
if not content:
content = base64.b64encode(self.placeholder(image='placeholder.png'))
return request.env['ir.http']._response_by_status(status, headers, image_base64)
if not image_base64:
image_base64 = base64.b64encode(self.placeholder(image='placeholder.png'))
headers = self.force_contenttype(headers, contenttype='image/png')
if not (width or height):
suffix = 'big' if field == 'image' else field.split('_')[-1]
if suffix in ('small', 'medium', 'large', 'big'):
content = getattr(odoo.tools, 'image_resize_image_%s' % suffix)(content)

image_base64 = getattr(odoo.tools, 'image_resize_image_%s' % suffix)(image_base64)

content = limited_image_resize(
content, width=width, height=height, crop=crop, upper_limit=upper_limit, avoid_if_small=avoid_if_small)
image_base64 = limited_image_resize(
image_base64, width=width, height=height, crop=crop, upper_limit=upper_limit, avoid_if_small=avoid_if_small)

image_base64 = base64.b64decode(content)
headers.append(('Content-Length', len(image_base64)))
response = request.make_response(image_base64, headers)
content = base64.b64decode(image_base64)
headers.append(('Content-Length', len(content)))
response = request.make_response(content, headers)
response.status_code = status
return response

@@ -82,27 +82,27 @@ def get_user_profile_avatar(self, user_id, field='image_large', width=0, height=

can_sudo = self._check_avatar_access(user_id, **post)
if can_sudo:
status, headers, content = request.env['ir.http'].sudo().binary_content(
status, headers, image_base64 = request.env['ir.http'].sudo().binary_content(
model='res.users', id=user_id, field=field,
default_mimetype='image/png')
else:
status, headers, content = request.env['ir.http'].binary_content(
status, headers, image_base64 = request.env['ir.http'].binary_content(
model='res.users', id=user_id, field=field,
default_mimetype='image/png')
if status == 301:
return request.env['ir.http']._response_by_status(status, headers, content)
return request.env['ir.http']._response_by_status(status, headers, image_base64)
if status == 304:
return werkzeug.wrappers.Response(status=304)

if not content:
content = self._get_default_avatar(field, headers, width, height)
if not image_base64:
image_base64 = self._get_default_avatar(field, headers, width, height)

content = tools.limited_image_resize(
content, width=width, height=height, crop=crop, upper_limit=upper_limit, avoid_if_small=avoid_if_small)
image_base64 = tools.limited_image_resize(
image_base64, width=width, height=height, crop=crop, upper_limit=upper_limit, avoid_if_small=avoid_if_small)

image_base64 = base64.b64decode(content)
headers.append(('Content-Length', len(image_base64)))
response = request.make_response(image_base64, headers)
content = base64.b64decode(image_base64)
headers.append(('Content-Length', len(content)))
response = request.make_response(content, headers)
response.status_code = status
return response

@@ -509,23 +509,23 @@ def slide_get_image(self, slide_id, field='image_medium', width=0, height=0, cro
if not slide:
raise werkzeug.exceptions.NotFound()

status, headers, content = request.env['ir.http'].sudo().binary_content(
status, headers, image_base64 = request.env['ir.http'].sudo().binary_content(
model='slide.slide', id=slide.id, field=field,
default_mimetype='image/png')
if status == 301:
return request.env['ir.http']._response_by_status(status, headers, content)
return request.env['ir.http']._response_by_status(status, headers, image_base64)
if status == 304:
return werkzeug.wrappers.Response(status=304)

if not content:
content = self._get_default_avatar(field, headers, width, height)
if not image_base64:
image_base64 = self._get_default_avatar(field, headers, width, height)

content = tools.limited_image_resize(
content, width=width, height=height, crop=crop, upper_limit=upper_limit, avoid_if_small=avoid_if_small)
image_base64 = tools.limited_image_resize(
image_base64, width=width, height=height, crop=crop, upper_limit=upper_limit, avoid_if_small=avoid_if_small)

image_base64 = base64.b64decode(content)
headers.append(('Content-Length', len(image_base64)))
response = request.make_response(image_base64, headers)
content = base64.b64decode(image_base64)
headers.append(('Content-Length', len(content)))
response = request.make_response(content, headers)
response.status_code = status
return response

0 comments on commit 1387082

Please sign in to comment.
You can’t perform that action at this time.