mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add all() method to UserConfig
This commit is contained in:
@@ -239,3 +239,21 @@ def shallow_compare_dict(source_dict, destination_dict, exclude=None):
|
||||
difference[key] = destination_dict[key]
|
||||
|
||||
return difference
|
||||
|
||||
|
||||
def flatten_dict(d, prefix='', separator='.'):
|
||||
"""
|
||||
Flatten netsted dictionaries into a single level by joining key names with a separator.
|
||||
|
||||
:param d: The dictionary to be flattened
|
||||
:param prefix: Initial prefix (if any)
|
||||
:param separator: The character to use when concatenating key names
|
||||
"""
|
||||
ret = {}
|
||||
for k, v in d.items():
|
||||
key = separator.join([prefix, k]) if prefix else k
|
||||
if type(v) is dict:
|
||||
ret.update(flatten_dict(v, prefix=key))
|
||||
else:
|
||||
ret[key] = v
|
||||
return ret
|
||||
|
Reference in New Issue
Block a user