mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Reworked the detection of local storages for the collectstatic 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.
This commit is contained in:
@@ -7,6 +7,7 @@ from optparse import make_option
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.management.base import CommandError, NoArgsCommand
|
||||
from django.utils.encoding import smart_text
|
||||
from django.utils.functional import LazyObject
|
||||
from django.utils.six.moves import input
|
||||
|
||||
from django.contrib.staticfiles import finders, storage
|
||||
@@ -144,8 +145,7 @@ class Command(NoArgsCommand):
|
||||
'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:
|
||||
@@ -192,6 +192,13 @@ class Command(NoArgsCommand):
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user