Skip to content
Snippets Groups Projects
Commit 32155eb4ba51 authored by Efflam Lemaillet's avatar Efflam Lemaillet :robot:
Browse files

add version id to entity #13

parent 3a2b326e89cc
No related branches found
No related tags found
No related merge requests found
Pipeline #152105 failed
...@@ -87,10 +87,6 @@ ...@@ -87,10 +87,6 @@
else: else:
oldkey = self.get_s3_key(entity, attr) oldkey = self.get_s3_key(entity, attr)
key = self.new_s3_key(entity, attr) key = self.new_s3_key(entity, attr)
# save S3 key
entity.cw_edited.edited_attribute(
attr, Binary(key.encode('utf-8')))
# copy Binary value, workaround for boto3 bug # copy Binary value, workaround for boto3 bug
# https://github.com/boto/s3transfer/issues/80 # https://github.com/boto/s3transfer/issues/80
# .read() is required since Binary can't wrap itself # .read() is required since Binary can't wrap itself
...@@ -109,6 +105,9 @@ ...@@ -109,6 +105,9 @@
**extra_args) **extra_args)
buffer.close() buffer.close()
# save S3 key
self.save_s3_key(entity, attr, s3_object.key, s3_object.value)
# when key is suffixed, move to final key in post commit event # when key is suffixed, move to final key in post commit event
# remove temporary key on rollback # remove temporary key on rollback
S3AddFileOp.get_instance(entity._cw).add_data( S3AddFileOp.get_instance(entity._cw).add_data(
...@@ -160,6 +159,16 @@ ...@@ -160,6 +159,16 @@
source.doexec(cnx, sql, attrs) source.doexec(cnx, sql, attrs)
entity.cw_edited = None entity.cw_edited = None
def save_s3_key(self, entity, attr, key, version_id=None):
if entity._cw.repo.config['s3-activate-object-versioning'] \
and version_id is not None:
id_string = (key, version_id).__repr__()
else :
id_string = key
entity.cw_edited.edited_attribute(
attr, Binary(id_string.encode('utf-8')))
def get_s3_key(self, entity, attr): def get_s3_key(self, entity, attr):
""" """
Return the S3 key of the S3 object storing the content of attribute Return the S3 key of the S3 object storing the content of attribute
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment