diff options
| -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() + + | 
