Skip to content

Commit

Permalink
Merge commit 'refs/pull/397/head' of https://github.com/camptocamp/od…
Browse files Browse the repository at this point in the history
…oo-cloud-platform into 16.0-6907
  • Loading branch information
docker-odoo committed May 8, 2024
2 parents 1005c36 + f16c6b7 commit f4d8776
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions attachment_s3/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
_logger.debug("Cannot 'import boto3'.")


class S3BucketClientRegistry(object):
bucket_dict = {}

@classmethod
def get_bucket_client(cls, bucket_name):
return cls.bucket_dict.get(bucket_name)

@classmethod
def set_bucket_client(cls, bucket_name, bucket_obj):
cls.bucket_dict[bucket_name] = bucket_obj


class IrAttachment(models.Model):
_inherit = "ir.attachment"

Expand Down Expand Up @@ -80,6 +92,10 @@ def _get_s3_bucket(self, name=None):

raise exceptions.UserError(msg)
# try:
# get instanciated bucket from bucket_dict
bucket = S3BucketClientRegistry.get_bucket_client(bucket_name)
if bucket:
return bucket
s3 = boto3.resource("s3", **params)
bucket = s3.Bucket(bucket_name)
exists = True
Expand All @@ -104,6 +120,8 @@ def _get_s3_bucket(self, name=None):
Bucket=bucket_name,
CreateBucketConfiguration={"LocationConstraint": region_name},
)
# store instanciated bucket to bucket_dict
S3BucketClientRegistry.set_bucket_client(bucket_name, bucket)
return bucket

@api.model
Expand Down

0 comments on commit f4d8776

Please sign in to comment.