diff --git a/django/contrib/staticfiles/apps.py b/django/contrib/staticfiles/apps.py index f406e161817..0911c0113d9 100644 --- a/django/contrib/staticfiles/apps.py +++ b/django/contrib/staticfiles/apps.py @@ -5,3 +5,4 @@ from django.utils.translation import ugettext_lazy as _ class StaticFilesConfig(AppConfig): name = 'django.contrib.staticfiles' verbose_name = _("Static Files") + ignore_patterns = ['CVS', '.*', '*~'] diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index 1e4a577b0be..db29ff73cc9 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import os from collections import OrderedDict +from django.apps import apps from django.contrib.staticfiles.finders import get_finders from django.contrib.staticfiles.storage import staticfiles_storage from django.core.files.storage import FileSystemStorage @@ -74,7 +75,7 @@ class Command(BaseCommand): parser.add_argument( '--no-default-ignore', action='store_false', 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): @@ -88,7 +89,7 @@ class Command(BaseCommand): self.dry_run = options['dry_run'] ignore_patterns = options['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.post_process = options['post_process'] diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt index e09bdaad49d..3e70d82f7ef 100644 --- a/docs/ref/contrib/staticfiles.txt +++ b/docs/ref/contrib/staticfiles.txt @@ -128,6 +128,24 @@ For a full list of options, refer to the commands own help by running:: $ 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`` -------------- diff --git a/tests/staticfiles_tests/apps/staticfiles_config.py b/tests/staticfiles_tests/apps/staticfiles_config.py new file mode 100644 index 00000000000..e48a0c8d99d --- /dev/null +++ b/tests/staticfiles_tests/apps/staticfiles_config.py @@ -0,0 +1,5 @@ +from django.contrib.staticfiles.apps import StaticFilesConfig + + +class IgnorePatternsAppConfig(StaticFilesConfig): + ignore_patterns = ['*.css'] diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index f0c6384df70..d2ae7e2ed5e 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -195,6 +195,20 @@ class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase): 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): """ Test ``--dry-run`` option for ``collectstatic`` management command.