Skip to content

Commit

Permalink
Compatibility with new middleware style
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke committed Sep 25, 2016
1 parent 5ecea56 commit 3739b69
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion example/middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class SetRemoteAddrFromForwardedFor(object):
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
class MiddlewareMixin(object): pass


class SetRemoteAddrFromForwardedFor(MiddlewareMixin):
"""
Middleware that sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, if the
latter is set. This is useful if you're sitting behind a reverse proxy that
Expand Down
2 changes: 1 addition & 1 deletion example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

SECRET_KEY = 'DO NOT USE THIS KEY!'

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'example.middleware.SetRemoteAddrFromForwardedFor',
'user_sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down
7 changes: 6 additions & 1 deletion user_sessions/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
except ImportError:
from django.utils.importlib import import_module

try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
class MiddlewareMixin(object): pass


class SessionMiddleware(object):
class SessionMiddleware(MiddlewareMixin):
"""
Middleware that provides ip and user_agent to the session store.
"""
Expand Down

0 comments on commit 3739b69

Please sign in to comment.