1
0
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:
Jeremy Stretch
2020-04-24 09:50:26 -04:00
parent d8494e44e7
commit 7c8c85e435
3 changed files with 40 additions and 0 deletions

View File

@@ -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