mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 17:08:41 -06:00
Optimize shallow_compare_dict()
This commit is contained in:
parent
4f12eccde6
commit
ed5fd140eb
@ -359,18 +359,18 @@ def prepare_cloned_fields(instance):
|
|||||||
return QueryDict(urlencode(params), mutable=True)
|
return QueryDict(urlencode(params), mutable=True)
|
||||||
|
|
||||||
|
|
||||||
def shallow_compare_dict(source_dict, destination_dict, exclude=None):
|
def shallow_compare_dict(source_dict, destination_dict, exclude=tuple()):
|
||||||
"""
|
"""
|
||||||
Return a new dictionary of the different keys. The values of `destination_dict` are returned. Only the equality of
|
Return a new dictionary of the different keys. The values of `destination_dict` are returned. Only the equality of
|
||||||
the first layer of keys/values is checked. `exclude` is a list or tuple of keys to be ignored.
|
the first layer of keys/values is checked. `exclude` is a list or tuple of keys to be ignored.
|
||||||
"""
|
"""
|
||||||
difference = {}
|
difference = {}
|
||||||
|
|
||||||
for key in destination_dict:
|
for key, value in destination_dict.items():
|
||||||
if source_dict.get(key) != destination_dict[key]:
|
if key in exclude:
|
||||||
if isinstance(exclude, (list, tuple)) and key in exclude:
|
continue
|
||||||
continue
|
if source_dict.get(key) != value:
|
||||||
difference[key] = destination_dict[key]
|
difference[key] = value
|
||||||
|
|
||||||
return difference
|
return difference
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user