From 4d8821fff11d8c1b148dc88b097c099e30481182 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 29 Oct 2018 23:14:22 +0100 Subject: Add update_data util to overload data dict properly --- ishtar_common/utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index e60fc0913..fb09c5876 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -145,6 +145,24 @@ def check_model_access_control(request, model, available_perms=None): return allowed, own +def update_data(data_1, data_2): + """ + Update a data directory taking account of key detail + """ + res = {} + if not isinstance(data_1, dict) or not isinstance(data_2, dict): + return data_1 + for k in data_1: + if k not in data_2: + res[k] = data_1[k] + else: + res[k] = update_data(data_1[k], data_2[k]) + for k in data_2: + if k not in data_1: + res[k] = data_2[k] + return res + + class MultiValueDict(BaseMultiValueDict): def get(self, *args, **kwargs): v = super(MultiValueDict, self).getlist(*args, **kwargs) -- cgit v1.2.3