From cb6342c87404264a5d46dac54c6cf2736321561e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 22 Dec 2021 10:13:08 -0500 Subject: [PATCH] Reference DEFAULT_USER_PREFERENCES for undefined preferences --- netbox/users/models.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/netbox/users/models.py b/netbox/users/models.py index 7b768b57f..0afc7d374 100644 --- a/netbox/users/models.py +++ b/netbox/users/models.py @@ -80,13 +80,25 @@ class UserConfig(models.Model): keys = path.split('.') # Iterate down the hierarchy, returning the default value if any invalid key is encountered - for key in keys: - if type(d) is dict and key in d: + try: + for key in keys: d = d.get(key) - else: - return default + return d + except (AttributeError, KeyError): + pass - return d + # If the key is not found in the user's config, check for an application-wide default + config = get_config() + d = config.DEFAULT_USER_PREFERENCES + try: + for key in keys: + d = d.get(key) + return d + except (AttributeError, KeyError): + pass + + # Finally, return the specified default value (if any) + return default def all(self): """