mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 16:48:36 +00:00
push update
This commit is contained in:
@@ -178,10 +178,35 @@ class IrAttachment(models.Model):
|
|||||||
else:
|
else:
|
||||||
return super(IrAttachment, self)._store_file_read(fname, bin_size)
|
return super(IrAttachment, self)._store_file_read(fname, bin_size)
|
||||||
|
|
||||||
|
|
||||||
|
def _inverse_datas(self):
|
||||||
|
location = self._storage()
|
||||||
|
for attach in self:
|
||||||
|
# compute the fields that depend on datas
|
||||||
|
value = attach.datas
|
||||||
|
bin_data = base64.b64decode(value) if value else b''
|
||||||
|
vals = {
|
||||||
|
'file_size': len(bin_data),
|
||||||
|
'checksum': self._compute_checksum(bin_data),
|
||||||
|
'index_content': self._index(bin_data, attach.datas_fname, attach.mimetype),
|
||||||
|
'store_fname': False,
|
||||||
|
'db_datas': value,
|
||||||
|
}
|
||||||
|
if value and location != 'db':
|
||||||
|
# save it to the filestore
|
||||||
|
vals['store_fname'] = self._file_write(value, vals['checksum'], mimetype=attach.mimetype)
|
||||||
|
vals['db_datas'] = False
|
||||||
|
|
||||||
|
# take current location in filestore to possibly garbage-collect it
|
||||||
|
fname = attach.store_fname
|
||||||
|
# write as superuser, as user probably does not have write access
|
||||||
|
super(IrAttachment, attach.sudo()).write(vals)
|
||||||
|
if fname:
|
||||||
|
self._file_delete(fname)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _store_file_write(self, key, bin_data):
|
def _store_file_write(self, key, bin_data, mimetype=False):
|
||||||
location = self.env.context.get('storage_location') or self._storage()
|
location = self.env.context.get('storage_location') or self._storage()
|
||||||
mimetype = self.env.context.get('mimetype') or self.mimetype
|
|
||||||
if location == 's3':
|
if location == 's3':
|
||||||
bucket = self._get_s3_bucket()
|
bucket = self._get_s3_bucket()
|
||||||
obj = bucket.Object(key=key)
|
obj = bucket.Object(key=key)
|
||||||
|
|||||||
@@ -164,10 +164,6 @@ class IrAttachment(models.Model):
|
|||||||
return len(bin_data) <= limit
|
return len(bin_data) <= limit
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_datas_related_values(self, data, mimetype):
|
|
||||||
self=self.with_context(mimetype=mimetype)
|
|
||||||
return super(IrAttachment, self)._get_datas_related_values(data, mimetype)
|
|
||||||
|
|
||||||
def _inverse_datas(self):
|
def _inverse_datas(self):
|
||||||
# override in order to store files that need fast access,
|
# override in order to store files that need fast access,
|
||||||
# we keep them in the database instead of the object storage
|
# we keep them in the database instead of the object storage
|
||||||
|
|||||||
Reference in New Issue
Block a user