Commit 3f00da53 authored by Diederik van der Boor's avatar Diederik van der Boor
Browse files

Move storage class to subpackage, add PRIVATE_STORAGE_CLASS setting

The default `private_storage.storage.PrivateStorage` class now points to
the class that was imported through the new setting, theirby preserving
backwards compatibility.
parent 8e9d90da
from django.conf import settings
PRIVATE_STORAGE_CLASS = getattr(settings, 'PRIVATE_STORAGE_CLASS', 'private_storage.storage.files.PrivateFileSystemStorage')
PRIVATE_STORAGE_ROOT = getattr(settings, 'PRIVATE_STORAGE_ROOT', None)
PRIVATE_STORAGE_SERVER = getattr(settings, 'PRIVATE_STORAGE_SERVER', 'django')
PRIVATE_STORAGE_AUTH_FUNCTION = getattr(settings, 'PRIVATE_STORAGE_AUTH_FUNCTION', 'private_storage.permissions.allow_superuser')
......
"""
Django Storage interface
"""
from django.utils.module_loading import import_string
from private_storage import appconfig
__all__ = (
'private_storage',
'PrivateStorage',
)
# Fetch the storage class
PrivateStorage = import_string(appconfig.PRIVATE_STORAGE_CLASS)
# Singleton instance.
private_storage = PrivateStorage()
"""
Django Storage interface
Django Storage interface, using the file system backend.
"""
from django.core.files.storage import FileSystemStorage
from django.core.urlresolvers import reverse_lazy
from django.utils.encoding import force_text
from . import appconfig
from private_storage import appconfig
__all__ = (
'private_storage',
'PrivateStorage',
)
class PrivateStorage(FileSystemStorage):
class PrivateFileSystemStorage(FileSystemStorage):
"""
Interface to the Django storage system,
storing the files in a private folder.
......@@ -22,7 +17,7 @@ class PrivateStorage(FileSystemStorage):
if location is None:
location = appconfig.PRIVATE_STORAGE_ROOT
super(PrivateStorage, self).__init__(
super(PrivateFileSystemStorage, self).__init__(
location=location,
base_url=base_url,
**kwargs
......@@ -36,8 +31,4 @@ class PrivateStorage(FileSystemStorage):
def url(self, name):
# Make sure reverse_lazy() is evaluated, as Python 3 won't do this here.
self.base_url = force_text(self.base_url)
return super(PrivateStorage, self).url(name)
# Singleton instance.
private_storage = PrivateStorage()
return super(PrivateFileSystemStorage, self).url(name)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment