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

7.0 binary field swift #1

Open
wants to merge 5 commits into
base: 7.0-binary-field
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 7 additions & 16 deletions binary_field/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def add(self, value):
'file_size': file_size,
}

def update(self, binary_uid, value):
def update(self, binary_uid, value, container=None):
_logger.debug('Delete binary model: %s, field: %s, uid: %s'
% (self.model_name, self.field_name, binary_uid))
self._file_delete(self.cr, SUPERUSER_ID, binary_uid)
Expand Down Expand Up @@ -183,11 +183,12 @@ def _fnct_write(self, obj, cr, uid, ids, field_name, value, args,
storage_obj = obj.pool['storage.configuration']
for record in obj.browse(cr, uid, ids, context=context):
storage = storage_obj.get_storage(cr, SUPERUSER_ID, field_name, record)
container = storage_obj._get_config(cr, SUPERUSER_ID, record._name, field_name).get('base_path')
binary_uid = record['%s_uid' % field_name]
if binary_uid:
res = storage.update(binary_uid, value)
res = storage.update(binary_uid, value, container=container)
else:
res = storage.add(value)
res = storage.add(value, container=container)
vals = self._prepare_binary_meta(
cr, uid, field_name, res, context=context)
record.write(vals)
Expand Down Expand Up @@ -273,20 +274,10 @@ def _fnct_write(self, obj, cr, uid, ids, field_name, value, args,

def _read_binary(self, storage, record, field_name, binary_uid,
Copy link
Member

@asaunier asaunier Oct 25, 2019

Choose a reason for hiding this comment

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

Could you explain (in the PR description?) why you remove this function?
Else it is hard for reviewers to figure out if this makes sense :)

Edit: OK I had not paid attention to the commit title. But more explanations are never too much :)

context=None):
if not context.get('bin_size_%s' % field_name)\
and not context.get('bin_base64_%s' % field_name)\
and not context.get('bin_base64')\
and storage.external_storage_server:
#if context.get('bin_size'):
# To avoid useless call by default for the image
# We never return the bin size but the url
# SO I remove the key in order to avoid the
# automatic conversion in the orm
#context.pop('bin_size')
if context.get('image_url'):
return storage.get_url(binary_uid)
else:
return super(ImageField, self)._read_binary(
storage, record, field_name, binary_uid, context=context)
return super(ImageField, self)._read_binary(
storage, record, field_name, binary_uid, context=context)

def _refresh_cache(self, obj, cr, uid, ids, field_name, context=None):
"""Refresh the cache of the small image
Expand Down
2 changes: 1 addition & 1 deletion binary_field/static/src/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ openerp.binary_field = function (instance) {
) {
return this.record[field].value;
} else {
return this._super();
return this._super(model, field, id, cache, options);
}
},
})
Expand Down