aboutsummaryrefslogtreecommitdiffstats
path: root/servo
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2021-05-12 20:53:36 +0300
committerFilipp Lepalaan <filipp@mac.com>2021-05-12 20:53:36 +0300
commit0eb9ec451e94f160072d8e7503a7afcf2585d7f3 (patch)
tree5a9c5de5c7743511f162ad6bc95339fe9e787db9 /servo
parent5826489fa46f5d143d84f476bbae082916fdff50 (diff)
downloadServo-0eb9ec451e94f160072d8e7503a7afcf2585d7f3.tar.gz
Servo-0eb9ec451e94f160072d8e7503a7afcf2585d7f3.tar.bz2
Servo-0eb9ec451e94f160072d8e7503a7afcf2585d7f3.zip
Fix custom middleware
Diffstat (limited to 'servo')
-rw-r--r--servo/lib/middleware.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/servo/lib/middleware.py b/servo/lib/middleware.py
index ec50188..0ee054a 100644
--- a/servo/lib/middleware.py
+++ b/servo/lib/middleware.py
@@ -11,7 +11,7 @@ if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS = [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
-class LoginRequiredMiddleware(object):
+class LoginRequiredMiddleware:
"""
Middleware that requires a user to be authenticated to view any page other
than LOGIN_URL. Exemptions to this requirement can optionally be specified
@@ -21,7 +21,12 @@ class LoginRequiredMiddleware(object):
Requires authentication middleware and template context processors to be
loaded. You'll get an error if they aren't.
"""
- def process_request(self, request):
+ def __init__(self, get_response):
+ self.get_response = get_response
+
+ def __call__(self, request):
+ response = self.get_response(request)
+
assert hasattr(request, 'user'), "The Login Required middleware\
requires authentication middleware to be installed. Edit your\
MIDDLEWARE_CLASSES setting to insert\
@@ -33,11 +38,19 @@ class LoginRequiredMiddleware(object):
if not any(m.match(path) for m in EXEMPT_URLS):
return HttpResponseRedirect(settings.LOGIN_URL)
+ return response
+
-class TimezoneMiddleware(object):
- def process_request(self, request):
+class TimezoneMiddleware:
+ def __init__(self, get_response):
+ self.get_response = get_response
+
+ def __call__(self, request):
+ response = self.get_response(request)
tzname = request.session.get('django_timezone')
if tzname:
timezone.activate(pytz.timezone(tzname))
else:
timezone.deactivate()
+
+ return response