From 39961bfac93cb13d9bbcc6897df847ecf9c33dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Thu, 25 Mar 2021 14:50:01 +0100 Subject: [PATCH] allow to set identity_func by ANALYTICAL_IDENTITY_FUNC settings --- analytical/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/analytical/utils.py b/analytical/utils.py index be70b70..f81ba35 100644 --- a/analytical/utils.py +++ b/analytical/utils.py @@ -84,10 +84,12 @@ def get_identity(context, prefix=None, identity_func=None, user=None): if user is None: user = get_user_from_context(context) if get_user_is_authenticated(user): - if identity_func is not None: - return identity_func(user) - else: + identity_func = getattr(settings, 'ANALYTICAL_IDENTITY_FUNC', + identity_func) + if identity_func is None: return user.get_username() + else: + return identity_func(user) except (KeyError, AttributeError): pass return None