diff options
author | Ashley Camba <ashwoods@gmail.com> | 2017-10-26 14:43:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-26 14:43:24 +0200 |
commit | e52c837859d4fbeafdd2bdfa7dc6331a953ca77f (patch) | |
tree | 08e22520b4ac96bc097d81e85114088f13c7732a | |
parent | 7f3e1b533f57aff624531e1afa402bb34a7a4cbe (diff) | |
download | raven-e52c837859d4fbeafdd2bdfa7dc6331a953ca77f.tar.gz |
fix(django): Avoid deprecation warnings when calling is_authenticated (#1112)
-rw-r--r-- | raven/contrib/django/client.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/raven/contrib/django/client.py b/raven/contrib/django/client.py index 1d84c1a..a161342 100644 --- a/raven/contrib/django/client.py +++ b/raven/contrib/django/client.py @@ -12,6 +12,7 @@ from __future__ import absolute_import import time import logging +from django import VERSION as DJANGO_VERSION from django.conf import settings from django.core.exceptions import SuspiciousOperation from django.http import HttpRequest @@ -37,6 +38,14 @@ from raven import breadcrumbs __all__ = ('DjangoClient',) +if DJANGO_VERSION < (1, 10): + def is_authenticated(request_user): + return request_user.is_authenticated() +else: + def is_authenticated(request_user): + return request_user.is_authenticated + + class _FormatConverter(object): def __init__(self, param_mapping): @@ -152,15 +161,9 @@ class DjangoClient(Client): return user_info try: - if hasattr(user, 'is_authenticated'): - # is_authenticated was a method in Django < 1.10 - if callable(user.is_authenticated): - authenticated = user.is_authenticated() - else: - authenticated = user.is_authenticated - if not authenticated: - return user_info - + authenticated = is_authenticated(user) + if not authenticated: + return user_info user_info['id'] = user.pk if hasattr(user, 'email'): |