Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #21867 -- Removed AppStaticStorage; app paths are now AppConfig…

…'s job.

AppStaticStorage only provided one thing over FileSystemStorage, which was
taking an app name (import path) and translating it into a filesystem
path. This is now something that should be done via app_config.path instead,
leaving AppStaticStorage with no reason for existence. It should be safe to
remove, as it was undocumented internal API.

There was some kind of feature in the AppDirectoriesFinder code related to a
"prefix" attribute on the storage class used by AppDirectoriesFinder. Since
this feature was undocumented, untested, and of unclear purpose, I removed it
as well.
  • Loading branch information...
commit f56c88a8eed91f68f6845bbf730f7b7361c5cfb1 1 parent 06bd181
@carljm carljm authored
View
29 django/contrib/staticfiles/finders.py
@@ -11,7 +11,6 @@
from django.utils import six, lru_cache
from django.contrib.staticfiles import utils
-from django.contrib.staticfiles.storage import AppStaticStorage
class BaseFinder(object):
@@ -110,24 +109,27 @@ def list(self, ignore_patterns):
class AppDirectoriesFinder(BaseFinder):
"""
A static files finder that looks in the directory of each app as
- specified in the source_dir attribute of the given storage class.
+ specified in the source_dir attribute.
"""
- storage_class = AppStaticStorage
+ storage_class = FileSystemStorage
+ source_dir = 'static'
def __init__(self, app_names=None, *args, **kwargs):
# The list of apps that are handled
self.apps = []
# Mapping of app names to storage instances
self.storages = OrderedDict()
- if app_names is None:
- app_configs = apps.get_app_configs()
- app_names = [app_config.name for app_config in app_configs]
- for app in app_names:
- app_storage = self.storage_class(app)
+ app_configs = apps.get_app_configs()
+ if app_names:
+ app_names = set(app_names)
+ app_configs = [ac for ac in app_configs if ac.name in app_names]
+ for app_config in app_configs:
+ app_storage = self.storage_class(
+ os.path.join(app_config.path, self.source_dir))
if os.path.isdir(app_storage.location):
- self.storages[app] = app_storage
- if app not in self.apps:
- self.apps.append(app)
+ self.storages[app_config.name] = app_storage
+ if app_config.name not in self.apps:
+ self.apps.append(app_config.name)
super(AppDirectoriesFinder, self).__init__(*args, **kwargs)
def list(self, ignore_patterns):
@@ -158,11 +160,6 @@ def find_in_app(self, app, path):
"""
storage = self.storages.get(app, None)
if storage:
- if storage.prefix:
- prefix = '%s%s' % (storage.prefix, os.sep)
- if not path.startswith(prefix):
- return None
- path = path[len(prefix):]
# only try to find a file if the source dir actually exists
if storage.exists(path):
matched_path = storage.path(path)
View
21 django/contrib/staticfiles/storage.py
@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from collections import OrderedDict
import hashlib
-from importlib import import_module
import os
import posixpath
import re
@@ -16,7 +15,6 @@
from django.utils.encoding import force_bytes, force_text
from django.utils.functional import LazyObject
from django.utils.six.moves.urllib.parse import unquote, urlsplit, urlunsplit, urldefrag
-from django.utils._os import upath
from django.contrib.staticfiles.utils import check_settings, matches_patterns
@@ -383,25 +381,6 @@ class ManifestStaticFilesStorage(ManifestFilesMixin, StaticFilesStorage):
pass
-class AppStaticStorage(FileSystemStorage):
- """
- A file system storage backend that takes an app module and works
- for the ``static`` directory of it.
- """
- prefix = None
- source_dir = 'static'
-
- def __init__(self, app, *args, **kwargs):
- """
- Returns a static file storage if available in the given app.
- """
- # app is the actual app module
- mod = import_module(app)
- mod_path = os.path.dirname(upath(mod.__file__))
- location = os.path.join(mod_path, self.source_dir)
- super(AppStaticStorage, self).__init__(location, *args, **kwargs)
-
-
class ConfiguredStorage(LazyObject):
def _setup(self):
self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
View
31 tests/staticfiles_tests/tests.py
@@ -824,37 +824,6 @@ def test_template_tag(self):
self.assertStaticRenders("testfile.txt", "/static/testfile.txt")
-class TestAppStaticStorage(TestCase):
- def setUp(self):
- # Creates a python module foo_module in a directory with non ascii
- # characters
- self.search_path = 'search_path_\xc3\xbc'
- os.mkdir(self.search_path)
- module_path = os.path.join(self.search_path, 'foo_module')
- os.mkdir(module_path)
- self.init_file = open(os.path.join(module_path, '__init__.py'), 'w')
- sys.path.append(os.path.abspath(self.search_path))
-
- def tearDown(self):
- self.init_file.close()
- sys.path.remove(os.path.abspath(self.search_path))
- shutil.rmtree(self.search_path)
-
- def test_app_with_non_ascii_characters_in_path(self):
- """
- Regression test for #18404 - Tests AppStaticStorage with a module that
- has non ascii characters in path and a non utf8 file system encoding
- """
- # set file system encoding to a non unicode encoding
- old_enc_func = sys.getfilesystemencoding
- sys.getfilesystemencoding = lambda: 'ISO-8859-1'
- try:
- st = storage.AppStaticStorage('foo_module')
- st.path('bar')
- finally:
- sys.getfilesystemencoding = old_enc_func
-
-
class CustomStaticFilesStorage(storage.StaticFilesStorage):
"""
Used in TestStaticFilePermissions
Please sign in to comment.
Something went wrong with that request. Please try again.