Kaydet (Commit) 6ca163d7 authored tarafından Alex Morozov's avatar Alex Morozov Kaydeden (comit) Claude Paroz

Fixed #25784 -- Prevented an exception on collectstatic help

Made the `manage.py help collectstatic` don't fail if the `STATIC_ROOT`
setting is empty.
üst 550107ff
...@@ -9,6 +9,7 @@ from django.core.files.storage import FileSystemStorage ...@@ -9,6 +9,7 @@ from django.core.files.storage import FileSystemStorage
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.core.management.color import no_style from django.core.management.color import no_style
from django.utils.encoding import smart_text from django.utils.encoding import smart_text
from django.utils.functional import cached_property
from django.utils.six.moves import input from django.utils.six.moves import input
...@@ -28,12 +29,14 @@ class Command(BaseCommand): ...@@ -28,12 +29,14 @@ class Command(BaseCommand):
self.post_processed_files = [] self.post_processed_files = []
self.storage = staticfiles_storage self.storage = staticfiles_storage
self.style = no_style() self.style = no_style()
@cached_property
def local(self):
try: try:
self.storage.path('') self.storage.path('')
except NotImplementedError: except NotImplementedError:
self.local = False return False
else: return True
self.local = True
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument('--noinput', '--no-input', parser.add_argument('--noinput', '--no-input',
......
...@@ -6,6 +6,8 @@ import shutil ...@@ -6,6 +6,8 @@ import shutil
import tempfile import tempfile
import unittest import unittest
from admin_scripts.tests import AdminScriptTestCase
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles import storage from django.contrib.staticfiles import storage
from django.contrib.staticfiles.management.commands import collectstatic from django.contrib.staticfiles.management.commands import collectstatic
...@@ -130,6 +132,18 @@ class TestConfiguration(StaticFilesTestCase): ...@@ -130,6 +132,18 @@ class TestConfiguration(StaticFilesTestCase):
storage.staticfiles_storage = staticfiles_storage storage.staticfiles_storage = staticfiles_storage
class TestCollectionHelpSubcommand(AdminScriptTestCase):
@override_settings(STATIC_ROOT=None)
def test_missing_settings_dont_prevent_help(self):
"""
Even if the STATIC_ROOT setting is not set, one can still call the
`manage.py help collectstatic` command.
"""
self.write_settings('settings.py', apps=['django.contrib.staticfiles'])
out, err = self.run_manage(['help', 'collectstatic'])
self.assertNoOutput(err)
class TestCollection(CollectionTestCase, TestDefaults): class TestCollection(CollectionTestCase, TestDefaults):
""" """
Test ``collectstatic`` management command. Test ``collectstatic`` management command.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment