Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.6.x] Reworked the detection of local storages for the collectstati…

…c command.

Before 4befb30 the detection was broken because we used isinstance
against a LazyObject rather than against a Storage class. That commit
fixed it by looking directly at the object wrapped by LazyObject.
This could however be a problem to anyone who subclasses the
collectstatic management Command and directly supplies a Storage class.

Refs #21581.

Backport of 7e27885 from master.
  • Loading branch information...
commit d6db48e5f6320ec3d76419b67c6a3819f078be5c 1 parent 76700c5
@loic loic authored timgraham committed
View
11 django/contrib/staticfiles/management/commands/collectstatic.py
@@ -8,6 +8,7 @@
from django.core.management.base import CommandError, NoArgsCommand
from django.utils.encoding import smart_text
from django.utils.datastructures import SortedDict
+from django.utils.functional import LazyObject
from django.utils.six.moves import input
from django.contrib.staticfiles import finders, storage
@@ -149,8 +150,7 @@ def handle_noargs(self, **options):
'location as specified in your settings'
)
- if (isinstance(self.storage._wrapped, FileSystemStorage) and
- self.storage.location):
+ if self.is_local_storage() and self.storage.location:
destination_path = self.storage.location
message.append(':\n\n %s\n\n' % destination_path)
else:
@@ -197,6 +197,13 @@ def log(self, msg, level=2):
if self.verbosity >= level:
self.stdout.write(msg)
+ def is_local_storage(self):
+ if issubclass(self.storage.__class__, LazyObject):
+ storage = self.storage._wrapped
+ else:
+ storage = self.storage
+ return isinstance(storage, FileSystemStorage)
+
def clear_dir(self, path):
"""
Deletes the given relative path using the destination storage backend.
View
26 tests/staticfiles_tests/tests.py
@@ -22,6 +22,9 @@
from django.contrib.staticfiles import finders, storage
+from .storage import DummyStorage
+
+
TEST_ROOT = os.path.dirname(upath(__file__))
TEST_SETTINGS = {
'DEBUG': True,
@@ -233,6 +236,29 @@ def test_location_empty(self):
'without having set the STATIC_ROOT setting to a filesystem path'):
call_command('collectstatic', interactive=False, verbosity=0, stderr=err)
+ def test_local_storage_detection_helper(self):
+ staticfiles_storage = storage.staticfiles_storage
+ try:
+ storage.staticfiles_storage._wrapped = empty
+ with override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage'):
+ command = collectstatic.Command()
+ self.assertTrue(command.is_local_storage())
+
+ storage.staticfiles_storage._wrapped = empty
+ with override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage'):
+ command = collectstatic.Command()
+ self.assertFalse(command.is_local_storage())
+
+ storage.staticfiles_storage = storage.FileSystemStorage()
+ command = collectstatic.Command()
+ self.assertTrue(command.is_local_storage())
+
+ storage.staticfiles_storage = DummyStorage()
+ command = collectstatic.Command()
+ self.assertFalse(command.is_local_storage())
+ finally:
+ storage.staticfiles_storage = staticfiles_storage
+
class TestCollection(CollectionTestCase, TestDefaults):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.