Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12.0 af29d67045486936f1ad5fe49b66e1c297f4560e #702

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
581fe21
:book: IAM has to be under Installation section
Nov 8, 2018
84f4a44
:ambulance: Product Variant were downloaded on server instead of pass…
Nov 8, 2018
e4eea91
:zap: Save resized image to s3 instead of passing original (big) image
Nov 8, 2018
5eec8b9
:rainbow: remove obsolete <odoo><data>
Nov 14, 2018
3d6c024
:rose: correct spelling in docs (#684)
Ramil-Mukhametzyanov Nov 16, 2018
bc375d9
:ambulance: when the "image_resize_image" function was called, they r…
Nov 2, 2018
c044207
Merge branch '11.0' into 11.0-bc375d9170a5576eee8e81d10c2ed980c3541b13
Nov 21, 2018
7f16ab8
:green_heart:
Nov 21, 2018
96ff29d
:ambulance: error openning popup
Nov 22, 2018
168f657
Merge pull request #687 from GabbasovDinar/11.0-web_preview-fix
Nov 26, 2018
3e1a737
:ambulance: forgot to delete when merge
Nov 22, 2018
27e5052
Merge pull request #686 from Rusllan/11.0-bc375d9170a5576eee8e81d10c2…
Dec 5, 2018
0fcbc5a
:ambulance: web_website fixes after odoo update https://github.com/od…
KolushovAlexandr Dec 3, 2018
af29d67
Merge pull request #698 from KolushovAlexandr/11.0-web_website-fixes_…
Dec 10, 2018
5f474ae
Merge remote-tracking branch 'upstream/11.0' into 12.0-af29d670454869…
KolushovAlexandr Dec 12, 2018
d99d3cd
:peace_symbol::one::two: some version conflicts in manifests are auto…
KolushovAlexandr Dec 12, 2018
5765e51
Merge branch '12.0' into 12.0-af29d67045486936f1ad5fe49b66e1c297f4560e
KolushovAlexandr Dec 12, 2018
66a4871
:shield: base_attendance fixed js tours
KolushovAlexandr Dec 4, 2018
4f1ca5a
:ambulance: minor fix after merging 11 to 12
KolushovAlexandr Dec 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions ir_attachment_url/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def is_url(value):
super_image_resize_image = tools.image_resize_image


def updated_image_resize_image(base64_source, size=(1024, 1024), encoding='base64', filetype=None, avoid_if_small=False):
def updated_image_resize_image(base64_source, size=(1024, 1024), encoding='base64', filetype=None, avoid_if_small=False, upper_limit=False):
source_for_check = base64_source.decode("utf-8") if isinstance(base64_source, bytes) else base64_source
if is_url(source_for_check):
return source_for_check
return super_image_resize_image(base64_source, size=size, encoding=encoding, filetype=filetype, avoid_if_small=avoid_if_small)
return super_image_resize_image(base64_source, size=size, encoding=encoding, filetype=filetype, avoid_if_small=avoid_if_small, upper_limit=upper_limit)


def updated_image_resize_image_big(base64_source, size=(1024, 1024), encoding='base64', filetype=None, avoid_if_small=True):
Expand All @@ -64,19 +64,24 @@ def updated_image_resize_image_small(base64_source, size=(64, 64), encoding='bas

def updated_image_get_resized_images(base64_source, return_big=False, return_medium=True, return_small=True,
big_name='image', medium_name='image_medium', small_name='image_small',
avoid_resize_big=True, avoid_resize_medium=False, avoid_resize_small=False):
avoid_resize_big=True, avoid_resize_medium=False, avoid_resize_small=False, sizes=None):
""" copy-pasted from odoo/tools/image.py::image_get_resized_images
because we rewrite image_resize_image function.
"""
if not sizes:
sizes = {}
return_dict = dict()
size_big = sizes.get(big_name, (1024, 1024))
size_medium = sizes.get(medium_name, (128, 128))
size_small = sizes.get(small_name, (64, 64))
if isinstance(base64_source, tools.pycompat.text_type):
base64_source = base64_source.encode('ascii')
if return_big:
return_dict[big_name] = updated_image_resize_image_big(base64_source, avoid_if_small=avoid_resize_big)
return_dict[big_name] = updated_image_resize_image_big(base64_source, avoid_if_small=avoid_resize_big, size=size_big)
if return_medium:
return_dict[medium_name] = updated_image_resize_image_medium(base64_source, avoid_if_small=avoid_resize_medium)
return_dict[medium_name] = updated_image_resize_image_medium(base64_source, avoid_if_small=avoid_resize_medium, size=size_medium)
if return_small:
return_dict[small_name] = updated_image_resize_image_small(base64_source, avoid_if_small=avoid_resize_small)
return_dict[small_name] = updated_image_resize_image_small(base64_source, avoid_if_small=avoid_resize_small, size=size_small)
return return_dict


Expand Down
61 changes: 24 additions & 37 deletions ir_attachment_url/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,10 @@ class IrHttp(models.AbstractModel):
_inherit = 'ir.http'

@classmethod
def _find_field_attachment(cls, env, m, f, id):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove it?

domain = [
('res_model', '=', m),
('res_field', '=', f),
('res_id', '=', id),
('type', '=', 'url'),
]
return env['ir.attachment'].sudo().search(domain)

@classmethod
def find_field_attachment(cls, env, model, field, obj):
is_attachment = env[model]._fields[field].attachment
is_product = model == 'product.product' and field.startswith('image')
if not (is_attachment or is_product):
return None

att = cls._find_field_attachment(env, model, field, obj.id)

if not att and model == 'product.product':
# Special case. Product.product's image are computed and
# use product.template's image in most cases. But due to
# this computation odoo pass binary data (by downloading it
# from s3) instead of url. So, make a workaround for it
att = cls._find_field_attachment(env, 'product.template', field, obj.product_tmpl_id.id)
return att

@classmethod
def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas', unique=False, filename=None, filename_field='datas_fname', download=False, mimetype=None, default_mimetype='application/octet-stream', access_token=None, env=None):
def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas',
unique=False, filename=None, filename_field='datas_fname', download=False,
mimetype=None, default_mimetype='application/octet-stream',
access_token=None, related_id=None, access_mode=None, env=None):
""" Get file, attachment or downloadable content
If the ``xmlid`` and ``id`` parameter is omitted, fetches the default value for the
binary field (via ``default_get``), otherwise fetches the field for
Expand All @@ -73,7 +49,7 @@ def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas
# get object and content
obj = None
if xmlid:
obj = env.ref(xmlid, False)
obj = cls._xmlid_to_obj(env, xmlid)
elif id and model in env.registry:
obj = env[model].browse(int(id))
# obj exists
Expand All @@ -83,7 +59,10 @@ def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas
# access token grant access
if model == 'ir.attachment' and access_token:
obj = obj.sudo()
if not consteq(obj.access_token or u'', access_token):
if access_mode:
if not cls._check_access_mode(env, id, access_mode, model, access_token=access_token, related_id=related_id):
return (403, [], None)
elif not consteq(obj.access_token or u'', access_token):
return (403, [], None)

# check read access
Expand All @@ -108,7 +87,8 @@ def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas
if module_resource_path.startswith(module_path):
with open(module_resource_path, 'rb') as f:
content = base64.b64encode(f.read())
# 'last_update' variable removed for lint error fix
# lint error fix (unused variable)
# last_update = pycompat.text_type(os.path.getmtime(module_resource_path))

if not module_resource_path:
module_resource_path = obj.url
Expand All @@ -117,12 +97,19 @@ def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas
status = 301
content = module_resource_path
else:
# begin redefined part of original binary_content of odoo/base/addons/ir/ir_http
att = env['ir.http'].find_field_attachment(env, model, field, obj)
if att:
content = att.url
status = 301

# begin redefined part of original binary_content of odoo/base/addons/models/ir_http
is_attachment = env[model]._fields[field].attachment
if is_attachment:
domain = [
('res_model', '=', model),
('res_field', '=', field),
('res_id', '=', obj.id),
('type', '=', 'url'),
]
att = env['ir.attachment'].sudo().search(domain)
if att:
content = att.url
status = 301
if not content:
content = obj[field] or ''
# end redefined part of original binary_content
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.