Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15094 - Added check for forgetting trailing comma in STATICFIL…

…ES_DIRS tuple. Also reorganized staticfiles settings-checks for better consistency.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15386 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7aad3d3fa8a8db8eb8ea9e64134d60b2400029f0 1 parent 74d485c
Carl Meyer carljm authored
8 django/contrib/staticfiles/finders.py
View
@@ -46,11 +46,19 @@ def __init__(self, apps=None, *args, **kwargs):
self.storages = SortedDict()
# Set of locations with static files
self.locations = set()
+ if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
+ raise ImproperlyConfigured(
+ "Your STATICFILES_DIRS setting is not a tuple or list; "
+ "perhaps you forgot a trailing comma?")
for root in settings.STATICFILES_DIRS:
if isinstance(root, (list, tuple)):
prefix, root = root
else:
prefix = ''
+ if os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
+ raise ImproperlyConfigured(
+ "The STATICFILES_DIRS setting should "
+ "not contain the STATIC_ROOT setting")
self.locations.add((prefix, root))
# Don't initialize multiple storages for the same location
for prefix, root in self.locations:
7 django/contrib/staticfiles/handlers.py
View
@@ -26,12 +26,7 @@ def get_base_dir(self):
return settings.STATIC_ROOT
def get_base_url(self):
- if not settings.STATIC_URL:
- raise ImproperlyConfigured("You're using the staticfiles app "
- "without having set the STATIC_URL setting. Set it to "
- "URL that handles the files served from STATIC_ROOT.")
- if settings.DEBUG:
- utils.check_settings()
+ utils.check_settings()
return settings.STATIC_URL
def _should_handle(self, path):
5 django/contrib/staticfiles/storage.py
View
@@ -10,7 +10,7 @@
class StaticFilesStorage(FileSystemStorage):
"""
Standard file system storage for static files.
-
+
The defaults for ``location`` and ``base_url`` are
``STATIC_ROOT`` and ``STATIC_URL``.
"""
@@ -28,8 +28,7 @@ def __init__(self, location=None, base_url=None, *args, **kwargs):
raise ImproperlyConfigured("You're using the staticfiles app "
"without having set the STATIC_URL setting. Set it to "
"URL that handles the files served from STATIC_ROOT.")
- if settings.DEBUG:
- utils.check_settings()
+ utils.check_settings()
super(StaticFilesStorage, self).__init__(location, base_url, *args, **kwargs)
15 django/contrib/staticfiles/utils.py
View
@@ -35,9 +35,13 @@ def get_files(storage, ignore_patterns=[], location=''):
def check_settings():
"""
- Checks if the MEDIA_(ROOT|URL) and STATIC_(ROOT|URL)
- settings have the same value.
+ Checks if the staticfiles settings have sane values.
+
"""
+ if not settings.STATIC_URL:
+ raise ImproperlyConfigured(
+ "You're using the staticfiles app "
+ "without having set the required STATIC_URL setting.")
if settings.MEDIA_URL == settings.STATIC_URL:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
@@ -45,10 +49,3 @@ def check_settings():
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
- for path in settings.STATICFILES_DIRS:
- # in case the item contains a prefix
- if isinstance(path, (list, tuple)):
- path = path[1]
- if os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(path):
- raise ImproperlyConfigured("The STATICFILES_DIRS setting should "
- "not contain the STATIC_ROOT setting")
22 tests/regressiontests/staticfiles_tests/tests.py
View
@@ -10,8 +10,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage
from django.core.management import call_command
-from django.db.models.loading import load_app
-from django.template import Template, Context
from django.test import TestCase
from django.utils._os import rmtree_errorhandler
@@ -383,7 +381,27 @@ def test_get_finder(self):
self.assertTrue(isinstance(finders.get_finder(
'django.contrib.staticfiles.finders.FileSystemFinder'),
finders.FileSystemFinder))
+
+ def test_get_finder_bad_classname(self):
self.assertRaises(ImproperlyConfigured,
finders.get_finder, 'django.contrib.staticfiles.finders.FooBarFinder')
+
+ def test_get_finder_bad_module(self):
self.assertRaises(ImproperlyConfigured,
finders.get_finder, 'foo.bar.FooBarFinder')
+
+
+class TestStaticfilesDirsType(TestCase):
+ """
+ We can't determine if STATICFILES_DIRS is set correctly just by looking at
+ the type, but we can determine if it's definitely wrong.
+ """
+ def setUp(self):
+ self.old_settings_dir = settings.STATICFILES_DIRS
+ settings.STATICFILES_DIRS = 'a string'
+
+ def tearDown(self):
+ settings.STATICFILES_DIRS = self.old_settings_dir
+
+ def test_non_tuple_raises_exception(self):
+ self.assertRaises(ImproperlyConfigured, finders.FileSystemFinder)
Please sign in to comment.
Something went wrong with that request. Please try again.