Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 0becb09

Browse files
committed
auth: DjangoAuthBackend: add compatiblity for Django 2.x
Signed-off-by: Florian Scherf <f.scherf@pengutronix.de>
1 parent a4d12b9 commit 0becb09

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

aiohttp_json_rpc/auth/django.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,19 @@ def get_user(self, request):
3939
return AnonymousUser()
4040

4141
def _is_authorized(self, request, method):
42+
def _user_is_authenticated(user):
43+
# between django 1.x and 2.x User.is_authenticated was changed
44+
# from an method to a boolean
45+
# this function adds support for both APIs
46+
47+
if callable(user.is_authenticated):
48+
return user.is_authenticated()
49+
50+
return user.is_authenticated
51+
4252
if hasattr(method, 'login_required') and (
4353
not request.user.is_active or
44-
not request.user.is_authenticated()):
54+
not _user_is_authenticated(request.user)):
4555
return False
4656

4757
# permission check

0 commit comments

Comments
 (0)