Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new-style MIDDLEWARE for latest django versions #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions django_common/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
from django.http import HttpResponsePermanentRedirect, HttpResponseRedirect
from django_common.session import SessionManager

try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object

WWW = 'www'


class WWWRedirectMiddleware(object):
class WWWRedirectMiddleware(MiddlewareMixin):
"""
Redirect requests for example from http://www.mysirw.com/* to http://mysite.com/*
"""
Expand All @@ -20,7 +25,7 @@ def process_request(self, request):
return None


class UserTimeTrackingMiddleware(object):
class UserTimeTrackingMiddleware(MiddlewareMixin):
"""
Tracking time user have been on site
"""
Expand All @@ -31,7 +36,7 @@ def process_request(self, request):
SessionManager(request).clear_usertime()


class SSLRedirectMiddleware(object):
class SSLRedirectMiddleware(MiddlewareMixin):
"""
Redirects all the requests that are non SSL to a SSL url
"""
Expand All @@ -42,7 +47,7 @@ def process_request(self, request):
return None


class NoSSLRedirectMiddleware(object):
class NoSSLRedirectMiddleware(MiddlewareMixin):
"""
Redirects if a non-SSL required view is hit. This middleware assumes a SSL protected view
has been decorated by the 'ssl_required' decorator (see decorators.py)
Expand Down