|
3 | 3 | import time |
4 | 4 | import uuid |
5 | 5 |
|
6 | | -from django import VERSION |
| 6 | +from django.utils.deprecation import MiddlewareMixin |
7 | 7 |
|
8 | 8 | from . import views |
9 | 9 |
|
10 | | -try: |
11 | | - from django.utils.deprecation import MiddlewareMixin |
12 | | -except ImportError: # pragma: no cover |
13 | | - MiddlewareMixin = object |
14 | | - |
15 | | - |
16 | | -# Computed once, reused in every request |
17 | | -_less_than_django_1_10 = VERSION < (1, 10) |
18 | | - |
19 | | - |
20 | | -def is_authenticated(user): # pragma: no cover |
21 | | - """Check if the user is authenticated but do it in a way that |
22 | | - it doesnt' cause a DeprecationWarning in Django >=1.10""" |
23 | | - if _less_than_django_1_10: |
24 | | - # Prior to Django 1.10, user.is_authenticated was a method |
25 | | - return user.is_authenticated() |
26 | | - return user.is_authenticated |
27 | | - |
28 | 10 |
|
29 | 11 | class DockerflowMiddleware(MiddlewareMixin): |
30 | 12 | """ |
@@ -66,7 +48,7 @@ def _build_extra_meta(self, request): |
66 | 48 | # modified earlier, so be sure to check for existence of these |
67 | 49 | # attributes before trying to use them. |
68 | 50 | if hasattr(request, "user"): |
69 | | - out["uid"] = is_authenticated(request.user) and request.user.pk or "" |
| 51 | + out["uid"] = request.user.is_authenticated and request.user.pk or "" |
70 | 52 | if hasattr(request, "_id"): |
71 | 53 | out["rid"] = request._id |
72 | 54 | if hasattr(request, "_start_timestamp"): |
|
0 commit comments