1. Zakhar Zibarov
  2. django-storages-multi

Commits

Zakhar Zibarov  committed 235b66a Draft

Fixed storage class name for valid serialization

  • Participants
  • Parent commits 547b818
  • Branches default

Comments (0)

Files changed (1)

File storages/backends/s3botomulti.py

View file
 SETTINGS_DICT = getattr(settings, 'STORAGES_S3BOTO_MULTI', {})
 for s3store in SETTINGS_DICT:
     # Wrap class definition inside function closure to avoid conflicts between custom instances
-    def init_s3boto_storage_custom():
+    def init_s3boto_storage_custom(class_name):
         ACCESS_KEY_NAME     = SETTINGS_DICT[s3store].get('AWS_ACCESS_KEY_ID', None)
         SECRET_KEY_NAME     = SETTINGS_DICT[s3store].get('AWS_SECRET_ACCESS_KEY', None)
         HEADERS             = SETTINGS_DICT[s3store].get('AWS_HEADERS', {})
 
         if IS_GZIPPED:
             from gzip import GzipFile
-    
+
         class S3BotoStorageCustom(S3BotoStorage):
             """
             S3 storage backend that looks for custom settings in STORAGES_CUSTOM_AWS_*
                     # and get keys from global AWS_ACCESS_KEY_ID setting or
                     # from environment variables
                     return super(S3BotoStorageCustom, self)._get_access_keys()
-        
-        return S3BotoStorageCustom
-    
+
+
+        return type(class_name, (S3BotoStorageCustom,), {})
+
     # Populate the module namespace with our custom initialized S3BotoStorageCustom
     # class giving it a name of S3BotoStorage_name where name is the dict key given
     # in the settings.
-    globals()['S3BotoStorage_'+s3store] = init_s3boto_storage_custom()
+    class_name = 'S3BotoStorage_' + s3store
+    globals()[class_name] = init_s3boto_storage_custom(class_name)