Removed some import-time dependencies on Django's settings.
Now you can import the file storage stuff and still call settings.configure() afterwards. There is still one import-time usage of settings in django.contrib.comments, but that's unavoidable. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9946 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
cf3071242a
commit
a08267bf6a
|
@ -4,11 +4,12 @@ import urlparse
|
|||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.utils.text import get_valid_filename
|
||||
from django.utils._os import safe_join
|
||||
from django.core.files import locks, File
|
||||
from django.core.files.move import file_move_safe
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.utils.functional import LazyObject
|
||||
from django.utils.text import get_valid_filename
|
||||
from django.utils._os import safe_join
|
||||
|
||||
__all__ = ('Storage', 'FileSystemStorage', 'DefaultStorage', 'default_storage')
|
||||
|
||||
|
@ -116,12 +117,20 @@ class Storage(object):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
# Needed by django.utils.functional.LazyObject (via DefaultStorage).
|
||||
def get_all_members(self):
|
||||
return self.__members__
|
||||
|
||||
class FileSystemStorage(Storage):
|
||||
"""
|
||||
Standard filesystem storage
|
||||
"""
|
||||
|
||||
def __init__(self, location=settings.MEDIA_ROOT, base_url=settings.MEDIA_URL):
|
||||
def __init__(self, location=None, base_url=None):
|
||||
if location is None:
|
||||
location = settings.MEDIA_ROOT
|
||||
if base_url is None:
|
||||
base_url = settings.MEDIA_URL
|
||||
self.location = os.path.abspath(location)
|
||||
self.base_url = base_url
|
||||
|
||||
|
@ -212,7 +221,9 @@ class FileSystemStorage(Storage):
|
|||
raise ValueError("This file is not accessible via a URL.")
|
||||
return urlparse.urljoin(self.base_url, name).replace('\\', '/')
|
||||
|
||||
def get_storage_class(import_path):
|
||||
def get_storage_class(import_path=None):
|
||||
if import_path is None:
|
||||
import_path = settings.DEFAULT_FILE_STORAGE
|
||||
try:
|
||||
dot = import_path.rindex('.')
|
||||
except ValueError:
|
||||
|
@ -227,5 +238,8 @@ def get_storage_class(import_path):
|
|||
except AttributeError:
|
||||
raise ImproperlyConfigured('Storage module "%s" does not define a "%s" class.' % (module, classname))
|
||||
|
||||
DefaultStorage = get_storage_class(settings.DEFAULT_FILE_STORAGE)
|
||||
class DefaultStorage(LazyObject):
|
||||
def _setup(self):
|
||||
self._wrapped = get_storage_class()()
|
||||
|
||||
default_storage = DefaultStorage()
|
||||
|
|
Loading…
Reference in New Issue