Skip to content

Commit

Permalink
Merge pull request #2333 from piotr1212/whitenoise_4
Browse files Browse the repository at this point in the history
Add support for WhiteNoise 4
  • Loading branch information
deniszh committed Aug 20, 2018
2 parents 5a904fd + 66e1de3 commit 824800a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ cairocffi
git+git://github.com/graphite-project/whisper.git#egg=whisper
# Ceres is optional
# git+git://github.com/graphite-project/ceres.git#egg=ceres
whitenoise==3.3.1
whitenoise
scandir
urllib3
six
15 changes: 15 additions & 0 deletions webapp/graphite/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
import raven
except ImportError:
raven = None
try:
import whitenoise
except ImportError:
whitenoise = False
else:
whitenoise_version = tuple(map(
int, getattr(whitenoise, '__version__', '0').split('.')))
# Configure WhiteNoise < 3.2 from wsgi.py
# http://whitenoise.evans.io/en/stable/changelog.html#v4-0
if whitenoise_version < (3, 2):
whitenoise = False

#Django settings below, do not touch!
APPEND_SLASH = False
Expand Down Expand Up @@ -70,6 +81,10 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

if whitenoise:
MIDDLEWARE += ('whitenoise.middleware.WhiteNoiseMiddleware', )

# SessionAuthenticationMiddleware is enabled by default since 1.10 and
# deprecated since 2.0
if DJANGO_VERSION < (1, 10):
Expand Down
8 changes: 6 additions & 2 deletions webapp/graphite/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
except ImportError:
whitenoise = False
else:
whitenoise_version = tuple(map(
int, getattr(whitenoise, '__version__', '0').split('.')))
# WhiteNoise < 2.0.1 does not support Python 2.6
if sys.version_info[:2] < (2, 7):
whitenoise_version = tuple(map(
int, getattr(whitenoise, '__version__', '0').split('.')))
if whitenoise_version < (2, 0, 1):
whitenoise = False
# Configure WhiteNoise >= 3.2 as middleware from app_settings.py
# http://whitenoise.evans.io/en/stable/changelog.html#v4-0
if whitenoise_version >= (3, 2):
whitenoise = False

if whitenoise:
from whitenoise.django import DjangoWhiteNoise
Expand Down

0 comments on commit 824800a

Please sign in to comment.