| 1 |
from django.conf import STATICFILES_STORAGE_ALIAS, settings |
| 2 |
from django.contrib.staticfiles.finders import get_finders |
| 3 |
from django.core.checks import Error |
| 4 |
|
| 5 |
E005 = Error( |
| 6 |
f"The STORAGES setting must define a '{STATICFILES_STORAGE_ALIAS}' storage.", |
| 7 |
id="staticfiles.E005", |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
def check_finders(app_configs=None, **kwargs): |
| 12 |
"""Check all registered staticfiles finders.""" |
| 13 |
errors = [] |
| 14 |
for finder in get_finders(): |
| 15 |
try: |
| 16 |
finder_errors = finder.check() |
| 17 |
except NotImplementedError: |
| 18 |
pass |
| 19 |
else: |
| 20 |
errors.extend(finder_errors) |
| 21 |
return errors |
| 22 |
|
| 23 |
|
| 24 |
def check_storages(app_configs=None, **kwargs): |
| 25 |
"""Ensure staticfiles is defined in STORAGES setting.""" |
| 26 |
errors = [] |
| 27 |
if STATICFILES_STORAGE_ALIAS not in settings.STORAGES: |
| 28 |
errors.append(E005) |
| 29 |
return errors |