diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-19 10:17:06 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-28 11:40:17 +0100 |
commit | c8791afe348c41aedcba9abbc3014e5db9c875f8 (patch) | |
tree | 9419d2afb458f94c36c5e7434ba5c2625e37f45a | |
parent | cdf6dea9e0c9cf099c7ee9594390a0ed6ce55107 (diff) | |
download | Ishtar-c8791afe348c41aedcba9abbc3014e5db9c875f8.tar.bz2 Ishtar-c8791afe348c41aedcba9abbc3014e5db9c875f8.zip |
Treatment n<->1: copy and merge data
-rw-r--r-- | archaeological_finds/models_treatments.py | 7 | ||||
-rw-r--r-- | ishtar_common/utils.py | 10 |
2 files changed, 14 insertions, 3 deletions
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index c7b888c0d..d92c98235 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -34,7 +34,8 @@ from ishtar_common.models import Document, GeneralType, \ ImageModel, BaseHistorizedItem, OwnPerms, HistoricalRecords, Person, \ Organization, ValueGetter, post_save_cache, ShortMenuItem, \ DashboardFormItem, ExternalIdManager -from ishtar_common.utils import cached_label_changed, get_current_year +from ishtar_common.utils import cached_label_changed, get_current_year, \ + update_data class TreatmentState(GeneralType): @@ -351,6 +352,10 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, current_documents.append(document.pk) new_find.documents.add(document) + # data + new_find.data = update_data(new_find.data, upstream_item.data, + merge=True) + upstream_item.downstream_treatment = self upstream_item.history_modifier = self.history_modifier upstream_item.save() diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 4f968af31..ff67fc470 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -145,18 +145,24 @@ def check_model_access_control(request, model, available_perms=None): return allowed, own -def update_data(data_1, data_2): +def update_data(data_1, data_2, merge=False): """ Update a data directory taking account of key detail """ res = {} if not isinstance(data_1, dict) or not isinstance(data_2, dict): + if data_2 and not data_1: + return data_2 + if not merge: + return data_1 + if data_2 and data_2 != data_1: + return data_1 + u" ; " + data_2 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]) + res[k] = update_data(data_1[k], data_2[k], merge=merge) for k in data_2: if k not in data_1: res[k] = data_2[k] |