summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/models_treatments.py7
-rw-r--r--ishtar_common/utils.py10
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]