Skip to content

Commit debad4c

Browse files
committed
Check if devserver overrides staticfiles runserver command
Ref: #100
1 parent 9ab4b78 commit debad4c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ You will need to include ``devserver`` in your ``INSTALLED_APPS``::
3434
'devserver',
3535
)
3636

37+
If you're using ``django.contrib.staticfiles`` or any other apps with management
38+
command ``runserver``, make sure to put ``devserver`` *above* any of them (or *below*,
39+
for ``Django<1.7``). Otherwise ``devserver`` will raise exception to ensure it is set up
40+
properly.
41+
3742
-----
3843
Usage
3944
-----

devserver/models.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
import django
12
from django.core import exceptions
3+
from django.core.exceptions import ImproperlyConfigured
24

35
from devserver.logger import GenericLogger
46

57

68
MODULES = []
79

810

11+
def check_installed_apps_configuration():
12+
"""
13+
Check the app is put in correct order in INSTALLED_APPS
14+
15+
django.contrib.staticfiles runserver command is likely to
16+
override devserver management command if put in wrong order.
17+
18+
Django had reversed order of management commands collection prior to 1.7
19+
https://code.djangoproject.com/ticket/16599
20+
"""
21+
from django.conf import settings
22+
try:
23+
staticfiles_index = settings.INSTALLED_APPS.index('django.contrib.staticfiles')
24+
devserver_index = settings.INSTALLED_APPS.index('devserver')
25+
except ValueError:
26+
pass
27+
else:
28+
latest_app_overrides = django.VERSION < (1, 7)
29+
if devserver_index < staticfiles_index and latest_app_overrides:
30+
raise ImproperlyConfigured(
31+
'Put "devserver" below "django.contrib.staticfiles" in INSTALLED_APPS to make it work')
32+
elif devserver_index > staticfiles_index and not latest_app_overrides:
33+
raise ImproperlyConfigured(
34+
'Put "devserver" above "django.contrib.staticfiles" in INSTALLED_APPS to make it work')
35+
36+
937
def load_modules():
1038
global MODULES
1139

@@ -37,4 +65,5 @@ def load_modules():
3765
MODULES.append(instance)
3866

3967
if not MODULES:
68+
check_installed_apps_configuration()
4069
load_modules()

0 commit comments

Comments
 (0)