From 2980f2ab9aabdea3a3b7ec343252889408690630 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 14 Aug 2011 18:15:04 +0000 Subject: [PATCH] Fixed #16629 -- Relaxed check for STATIC_ROOT and STATIC_URL settings slightly to only raise an exception if really needed. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16617 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/staticfiles/storage.py | 16 ++++++++-------- django/contrib/staticfiles/utils.py | 8 +++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index e3914efdfa3..a804c5626c8 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -30,17 +30,17 @@ class StaticFilesStorage(FileSystemStorage): location = settings.STATIC_ROOT if base_url is None: base_url = settings.STATIC_URL - if not location: - raise ImproperlyConfigured("You're using the staticfiles app " - "without having set the STATIC_ROOT setting.") - # check for None since we might use a root URL (``/``) - if base_url is None: - raise ImproperlyConfigured("You're using the staticfiles app " - "without having set the STATIC_URL setting.") - check_settings() + check_settings(base_url) super(StaticFilesStorage, self).__init__(location, base_url, *args, **kwargs) + def path(self, name): + if not self.location: + raise ImproperlyConfigured("You're using the staticfiles app " + "without having set the STATIC_ROOT " + "setting to a filesystem path.") + return super(StaticFilesStorage, self).path(name) + class CachedFilesMixin(object): patterns = ( diff --git a/django/contrib/staticfiles/utils.py b/django/contrib/staticfiles/utils.py index 9aee9280638..55ea3cf06b8 100644 --- a/django/contrib/staticfiles/utils.py +++ b/django/contrib/staticfiles/utils.py @@ -37,16 +37,18 @@ def get_files(storage, ignore_patterns=None, location=''): for fn in get_files(storage, ignore_patterns, dir): yield fn -def check_settings(): +def check_settings(base_url=None): """ Checks if the staticfiles settings have sane values. """ - if not settings.STATIC_URL: + if base_url is not None: + base_url = settings.STATIC_URL + if not base_url: raise ImproperlyConfigured( "You're using the staticfiles app " "without having set the required STATIC_URL setting.") - if settings.MEDIA_URL == settings.STATIC_URL: + if settings.MEDIA_URL == base_url: raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL " "settings must have different values") if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and