multitenant: redo storage backend by overriding location property (#63725)
This commit is contained in:
parent
1f0d890048
commit
46b334579f
|
@ -2,6 +2,7 @@ import os
|
|||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
from django.core.files import File
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.db import connection
|
||||
from django.utils._os import safe_join
|
||||
|
@ -18,15 +19,11 @@ __all__ = ('TenantFileSystemStorage',)
|
|||
|
||||
|
||||
class TenantFileSystemStorage(FileSystemStorage, TenantStorageMixin):
|
||||
'''Lookup files first in $TENANT_BASE/<tenant.schema>/media/ then in default location'''
|
||||
'''Lookup files in $TENANT_BASE/<tenant.schema>/media/'''
|
||||
|
||||
def path(self, name):
|
||||
@property
|
||||
def location(self):
|
||||
if connection.tenant:
|
||||
location = safe_join(settings.TENANT_BASE, connection.tenant.domain_url, 'media')
|
||||
return safe_join(settings.TENANT_BASE, connection.tenant.domain_url, 'media')
|
||||
else:
|
||||
location = self.location
|
||||
try:
|
||||
path = safe_join(location, name)
|
||||
except ValueError:
|
||||
raise SuspiciousOperation("Attempted access to '%s' denied." % name)
|
||||
return os.path.normpath(path)
|
||||
return os.path.abspath(self.base_location)
|
||||
|
|
Loading…
Reference in New Issue