Made daphne installable as a Django app.

Added system check to ensure daphne is installed before
django.contrib.staticfiles.
This commit is contained in:
Carlton Gibson 2022-08-05 15:49:31 +02:00
parent 438b7ad06d
commit 43237a4258
2 changed files with 40 additions and 0 deletions

20
daphne/apps.py Normal file
View File

@ -0,0 +1,20 @@
# Import the server here to ensure the reactor is installed very early on in case other
# packages import twisted.internet.reactor (e.g. raven does this).
import daphne.server # noqa: F401
try:
# Allow that Django is not installed.
from django.apps import AppConfig
from django.core import checks
from .checks import check_daphne_installed
except ImportError:
pass
else:
class DaphneConfig(AppConfig):
name = "daphne"
verbose_name = "Daphne"
def ready(self):
checks.register(check_daphne_installed, checks.Tags.staticfiles)

20
daphne/checks.py Normal file
View File

@ -0,0 +1,20 @@
# Django system check to ensure daphne app is listed in INSTALLED_APPS before django.contrib.staticfiles.
from django.core.checks import Error, register
@register()
def check_daphne_installed(app_configs, **kwargs):
from daphne.apps import DaphneConfig
from django.apps import apps
from django.contrib.staticfiles.apps import StaticFilesConfig
for app in apps.get_app_configs():
if isinstance(app, DaphneConfig):
return []
if isinstance(app, StaticFilesConfig):
return [
Error(
"Daphne must be listed before django.contrib.staticfiles in INSTALLED_APPS.",
id="daphne.E001",
)
]