summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-09-21 15:58:32 +0000
committerJannis Leidel <jannis@leidel.info>2011-09-21 15:58:32 +0000
commitc4cc8756437de2c9b508910ebe84f75a8d98d699 (patch)
tree45a83c2c0b6e9e6163aaad73b419ecffe9232dd6 /django
parenteb5df8e98db5c5592d5f0a0ca4680f9368ed0db5 (diff)
Fixed #16703 -- Raise an exception if the storage location of the DefaultStorageFinder is empty.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16863 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/staticfiles/finders.py15
-rw-r--r--django/core/files/storage.py6
2 files changed, 17 insertions, 4 deletions
diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py
index 45bf4a1023..7b4c7c8178 100644
--- a/django/contrib/staticfiles/finders.py
+++ b/django/contrib/staticfiles/finders.py
@@ -3,7 +3,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage, Storage, FileSystemStorage
from django.utils.datastructures import SortedDict
-from django.utils.functional import memoize, LazyObject
+from django.utils.functional import empty, memoize, LazyObject
from django.utils.importlib import import_module
from django.utils._os import safe_join
@@ -133,7 +133,7 @@ class AppDirectoriesFinder(BaseFinder):
List all files in all app storages.
"""
for storage in self.storages.itervalues():
- if storage.exists(''): # check if storage location exists
+ if storage.exists(''): # check if storage location exists
for path in utils.get_files(storage, ignore_patterns):
yield path, storage
@@ -210,12 +210,21 @@ class BaseStorageFinder(BaseFinder):
for path in utils.get_files(self.storage, ignore_patterns):
yield path, self.storage
+
class DefaultStorageFinder(BaseStorageFinder):
"""
A static files finder that uses the default storage backend.
"""
storage = default_storage
+ def __init__(self, *args, **kwargs):
+ super(DefaultStorageFinder, self).__init__(*args, **kwargs)
+ base_location = getattr(self.storage, 'base_location', empty)
+ if not base_location:
+ raise ImproperlyConfigured("The storage backend of the "
+ "staticfiles finder %r doesn't have "
+ "a valid location." % self.__class__)
+
def find(path, all=False):
"""
@@ -237,10 +246,12 @@ def find(path, all=False):
# No match.
return all and [] or None
+
def get_finders():
for finder_path in settings.STATICFILES_FINDERS:
yield get_finder(finder_path)
+
def _get_finder(import_path):
"""
Imports the staticfiles finder class described by import_path, where
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 73126a3cb9..aa62175819 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -12,7 +12,8 @@ from django.utils.encoding import force_unicode, filepath_to_uri
from django.utils.functional import LazyObject
from django.utils.importlib import import_module
from django.utils.text import get_valid_filename
-from django.utils._os import safe_join
+from django.utils._os import safe_join, abspathu
+
__all__ = ('Storage', 'FileSystemStorage', 'DefaultStorage', 'default_storage')
@@ -145,9 +146,10 @@ class FileSystemStorage(Storage):
def __init__(self, location=None, base_url=None):
if location is None:
location = settings.MEDIA_ROOT
+ self.base_location = location
+ self.location = abspathu(self.base_location)
if base_url is None:
base_url = settings.MEDIA_URL
- self.location = os.path.abspath(location)
self.base_url = base_url
def _open(self, name, mode='rb'):