From 121fe99cf54f127825e454319d4d5d2806d04a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alieh=20Ryma=C5=A1e=C5=ADski?= Date: Tue, 28 Jun 2022 16:52:55 +0000 Subject: [PATCH] Simplify is_authenticated check This attribute is defined on request.user from Django 1.10 or a comparably ancient version. --- auditlog/middleware.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/auditlog/middleware.py b/auditlog/middleware.py index bc64dc5..aa7b123 100644 --- a/auditlog/middleware.py +++ b/auditlog/middleware.py @@ -20,9 +20,7 @@ class AuditlogMiddleware: else: remote_addr = request.META.get("REMOTE_ADDR") - if hasattr(request, "user") and getattr( - request.user, "is_authenticated", False - ): + if hasattr(request, "user") and request.user.is_authenticated: context = set_actor(actor=request.user, remote_addr=remote_addr) else: context = contextlib.nullcontext()