2
0
Эх сурвалжийг харах

Reference DEFAULT_USER_PREFERENCES for undefined preferences

jeremystretch 4 жил өмнө
parent
commit
cb6342c874
1 өөрчлөгдсөн 17 нэмэгдсэн , 5 устгасан
  1. 17 5
      netbox/users/models.py

+ 17 - 5
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
+
+        # 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
 
-        return d
+        # Finally, return the specified default value (if any)
+        return default
 
     def all(self):
         """