Skip to content

Commit 379f020

Browse files
spapasjpic
authored andcommitted
Changes to make it compatible with django 2.x
1 parent ae72285 commit 379f020

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

rules_light/middleware.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"""
55
from __future__ import unicode_literals
66

7-
from django import template
8-
from django import http
7+
from django import template, http, VERSION
8+
99
from django.conf import settings
1010

1111
from .exceptions import RulesLightException
@@ -24,7 +24,19 @@ def process_exception(self, request, exception):
2424
if not isinstance(exception, RulesLightException):
2525
return
2626

27-
ctx = template.RequestContext(request, dict(exception=exception,
28-
settings=settings))
27+
if VERSION > (1, 8):
28+
ctx = dict(exception=exception, settings=settings)
29+
else:
30+
ctx = template.RequestContext(request, dict(exception=exception,
31+
settings=settings))
2932
return http.HttpResponseForbidden(template.loader.render_to_string(
3033
'rules_light/exception.html', ctx))
34+
35+
def __init__(self, get_response):
36+
super(Middleware, self).__init__()
37+
# Support Django 1.10 middleware.
38+
if get_response is not None:
39+
self.get_response = get_response
40+
41+
def __call__(self, request):
42+
return self.get_response(request)

0 commit comments

Comments
 (0)