1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #2495: Enable deep-merging of config context data

This commit is contained in:
Jeremy Stretch
2018-12-05 14:34:49 -05:00
parent d3d6c83fbb
commit 686a65880e
4 changed files with 108 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals
from collections import OrderedDict
import datetime
import json
import six
@ -109,3 +110,16 @@ def serialize_object(obj, extra=None):
data.update(extra)
return data
def deepmerge(original, new):
"""
Deep merge two dictionaries (new into original) and return a new dict
"""
merged = OrderedDict(original)
for key, val in new.items():
if key in original and isinstance(original[key], dict) and isinstance(val, dict):
merged[key] = deepmerge(original[key], val)
else:
merged[key] = val
return merged