From b3af9bf6f9e23d974d8fa2d85786f44d9245ddeb Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 24 Oct 2019 15:42:00 +0200 Subject: [PATCH 1/5] Fix call to super in JS widget --- binary_field/static/src/js/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binary_field/static/src/js/widget.js b/binary_field/static/src/js/widget.js index dc8a6586dff..e10c6149d0f 100644 --- a/binary_field/static/src/js/widget.js +++ b/binary_field/static/src/js/widget.js @@ -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); } }, }) From 992182cc05a12383642a686153169fdd51bff4ee Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 24 Oct 2019 15:43:04 +0200 Subject: [PATCH 2/5] Drop _read_binary override to ensure binary is read from swift --- binary_field/fields.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/binary_field/fields.py b/binary_field/fields.py index 1b04676cd32..e5f3b80c159 100644 --- a/binary_field/fields.py +++ b/binary_field/fields.py @@ -271,23 +271,6 @@ def _fnct_write(self, obj, cr, uid, ids, field_name, value, args, obj, cr, uid, ids, name, context=context) return True - def _read_binary(self, storage, record, field_name, binary_uid, - 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') - return storage.get_url(binary_uid) - else: - 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 :params ids: list of object id to refresh From 3b26dfa7e3c9294d00cf47acd48879bcd49869ef Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 26 Nov 2019 14:49:00 +0100 Subject: [PATCH 3/5] Restore _read_binary override to return URL only with specific context key --- binary_field/fields.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/binary_field/fields.py b/binary_field/fields.py index e5f3b80c159..8a7bdb2622f 100644 --- a/binary_field/fields.py +++ b/binary_field/fields.py @@ -271,6 +271,13 @@ def _fnct_write(self, obj, cr, uid, ids, field_name, value, args, obj, cr, uid, ids, name, context=context) return True + def _read_binary(self, storage, record, field_name, binary_uid, + context=None): + if context.get('image_url'): + return storage.get_url(binary_uid) + 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 :params ids: list of object id to refresh From 3eb9d25fd4293678ce490094249220dc9bd66fa9 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 26 Nov 2019 14:49:24 +0100 Subject: [PATCH 4/5] Propagate the container from storage configuration to storage class --- binary_field/fields.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/binary_field/fields.py b/binary_field/fields.py index 8a7bdb2622f..eabcd1cec36 100644 --- a/binary_field/fields.py +++ b/binary_field/fields.py @@ -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) From cd514c488f994c602093c65d1a14a6f14ff575fe Mon Sep 17 00:00:00 2001 From: sebalix Date: Fri, 31 Jan 2020 15:44:00 +0100 Subject: [PATCH 5/5] fixup! Propagate the container from storage configuration to storage class --- binary_field/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binary_field/fields.py b/binary_field/fields.py index eabcd1cec36..80c0ec80716 100644 --- a/binary_field/fields.py +++ b/binary_field/fields.py @@ -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)