Fixed #20189 -- Allowed customizing staticfiles ignored_patterns list
Thanks Tim Graham for the review.
This commit is contained in:
parent
6f5fcfc6d2
commit
f4c2b8e04a
|
@ -5,3 +5,4 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
class StaticFilesConfig(AppConfig):
|
class StaticFilesConfig(AppConfig):
|
||||||
name = 'django.contrib.staticfiles'
|
name = 'django.contrib.staticfiles'
|
||||||
verbose_name = _("Static Files")
|
verbose_name = _("Static Files")
|
||||||
|
ignore_patterns = ['CVS', '.*', '*~']
|
||||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.contrib.staticfiles.finders import get_finders
|
from django.contrib.staticfiles.finders import get_finders
|
||||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||||
from django.core.files.storage import FileSystemStorage
|
from django.core.files.storage import FileSystemStorage
|
||||||
|
@ -74,7 +75,7 @@ class Command(BaseCommand):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--no-default-ignore', action='store_false',
|
'--no-default-ignore', action='store_false',
|
||||||
dest='use_default_ignore_patterns', default=True,
|
dest='use_default_ignore_patterns', default=True,
|
||||||
help="Don't ignore the common private glob-style patterns 'CVS', '.*' and '*~'.",
|
help="Don't ignore the common private glob-style patterns (defaults to 'CVS', '.*' and '*~').",
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_options(self, **options):
|
def set_options(self, **options):
|
||||||
|
@ -88,7 +89,7 @@ class Command(BaseCommand):
|
||||||
self.dry_run = options['dry_run']
|
self.dry_run = options['dry_run']
|
||||||
ignore_patterns = options['ignore_patterns']
|
ignore_patterns = options['ignore_patterns']
|
||||||
if options['use_default_ignore_patterns']:
|
if options['use_default_ignore_patterns']:
|
||||||
ignore_patterns += ['CVS', '.*', '*~']
|
ignore_patterns += apps.get_app_config('staticfiles').ignore_patterns
|
||||||
self.ignore_patterns = list(set(ignore_patterns))
|
self.ignore_patterns = list(set(ignore_patterns))
|
||||||
self.post_process = options['post_process']
|
self.post_process = options['post_process']
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,24 @@ For a full list of options, refer to the commands own help by running::
|
||||||
|
|
||||||
$ python manage.py collectstatic --help
|
$ python manage.py collectstatic --help
|
||||||
|
|
||||||
|
Customizing the ignored pattern list
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. versionadded:: 1.10
|
||||||
|
|
||||||
|
The default ignored pattern list, ``['CVS', '.*', '*~']``, can be customized in
|
||||||
|
a more persistent way than providing the ``--ignore`` command option at each
|
||||||
|
``collectstatic`` invocation. Provide a custom :class:`~django.apps.AppConfig`
|
||||||
|
class, override the ``ignore_patterns`` attribute of this class and specify
|
||||||
|
that class path inside your :setting:`INSTALLED_APPS` setting:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from django.contrib.staticfiles.apps import StaticFilesConfig
|
||||||
|
|
||||||
|
class MyStaticFilesConfig(StaticFilesConfig):
|
||||||
|
ignore_patterns = [...] # your custom ignore list
|
||||||
|
|
||||||
``findstatic``
|
``findstatic``
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
from django.contrib.staticfiles.apps import StaticFilesConfig
|
||||||
|
|
||||||
|
|
||||||
|
class IgnorePatternsAppConfig(StaticFilesConfig):
|
||||||
|
ignore_patterns = ['*.css']
|
|
@ -195,6 +195,20 @@ class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase):
|
||||||
self.assertFileContains('test/CVS', 'should be ignored')
|
self.assertFileContains('test/CVS', 'should be ignored')
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(INSTALLED_APPS=[
|
||||||
|
'staticfiles_tests.apps.staticfiles_config.IgnorePatternsAppConfig',
|
||||||
|
'staticfiles_tests.apps.test',
|
||||||
|
])
|
||||||
|
class TestCollectionCustomIgnorePatterns(CollectionTestCase):
|
||||||
|
def test_custom_ignore_patterns(self):
|
||||||
|
"""
|
||||||
|
A custom ignore_patterns list, ['*.css'] in this case, can be specified
|
||||||
|
in an AppConfig definition.
|
||||||
|
"""
|
||||||
|
self.assertFileNotFound('test/nonascii.css')
|
||||||
|
self.assertFileContains('test/.hidden', 'should be ignored')
|
||||||
|
|
||||||
|
|
||||||
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
|
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
Test ``--dry-run`` option for ``collectstatic`` management command.
|
Test ``--dry-run`` option for ``collectstatic`` management command.
|
||||||
|
|
Loading…
Reference in New Issue