diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-10-29 23:14:22 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-10-29 23:14:22 +0100 |
commit | 029b74dfa13919222138734b41265642e30494ab (patch) | |
tree | 7702a5f61b7295f20c8690ed51bb0bc9b63d2e9f | |
parent | ed56b61fb8cc09467175d8fb97ec6a8d459e92e7 (diff) | |
download | Ishtar-029b74dfa13919222138734b41265642e30494ab.tar.bz2 Ishtar-029b74dfa13919222138734b41265642e30494ab.zip |
Add update_data util to overload data dict properly
-rw-r--r-- | ishtar_common/utils.py | 18 | ||||
-rw-r--r-- | scripts/restore_find_data.py | 19 |
2 files changed, 37 insertions, 0 deletions
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) diff --git a/scripts/restore_find_data.py b/scripts/restore_find_data.py new file mode 100644 index 000000000..3dbbc4518 --- /dev/null +++ b/scripts/restore_find_data.py @@ -0,0 +1,19 @@ +""" +Restore find data on destructive import +""" + +from ishtar_common.utils import update_data + +from archaeological_finds.models import Find + + +for item in Find.objects.all()[0:50]: + data = item.data + for h in item.history.order_by('-history_modifier_id', '-history_date', + '-history_id').all(): + data = update_data(data, h.data) + item.data = data + item.skip_history_when_saving = True + item.save() + + |