summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r--ishtar_common/data_importer.py50
1 files changed, 24 insertions, 26 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 7bdade5ab..584917c8e 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -1568,7 +1568,7 @@ class Importer(object):
field_name = field_name[idx_fields]
if type(force_new) in (list, tuple):
force_new = force_new[idx_fields]
- if formater.concat:
+ if formater.concat and any(formater.concat):
self.concats.add(field_name)
concat_str = formater.concat_str
if type(formater.concat_str) in (list, tuple):
@@ -2141,42 +2141,40 @@ class Importer(object):
raise self._get_does_not_exist_in_db_error(cls, dct)
dct["defaults"] = defaults.copy()
- if not created and not path and self.UNICITY_KEYS:
+ # manage default values and concatenation
+ if not created and not path and self.UNICITY_KEYS and obj is not None:
updated_dct = {}
- if self.conservative_import:
- for k in dct["defaults"]:
- new_val = dct["defaults"][k]
- if new_val is None or new_val == "":
- continue
- val = getattr(obj, k)
- if val is None or val == "":
- updated_dct[k] = new_val
- elif (
- k in self.concats
- and type(val) == str
- and type(new_val) == str
- ):
- updated_dct[k] = val + "\n" + new_val
- else:
- for k in dct["defaults"]:
- new_val = dct["defaults"][k]
- if new_val is None or new_val == "":
- continue
- if obj and k == "data":
- updated_dct[k] = update_data(obj.data, new_val)
- else:
- updated_dct[k] = new_val
+ for k in dct["defaults"]:
+ new_val = dct["defaults"][k]
+ if new_val is None or new_val == "":
+ continue
+ val = getattr(obj, k)
+ if val is None or val == "":
+ updated_dct[k] = new_val
+ elif obj and k == "data":
+ updated_dct[k] = update_data(obj.data, new_val)
+ elif (
+ k in self.concats
+ and type(val) == str
+ and type(new_val) == str
+ ):
+ sep = ""
+ if k in self.concat_str:
+ sep = self.concat_str[k]
+ updated_dct[k] = val + sep + new_val
if updated_dct:
if self.simulate:
self.updated_objects[-1][-1] = updated_dct
else:
+ obj.__class__.objects.filter(pk=obj.pk).update(
+ **updated_dct
+ )
for k in updated_dct:
setattr(obj, k, updated_dct[k])
obj._timestamp = self.timestamp
obj._queue = "low_priority"
if hasattr(obj, "no_post_process"):
obj.no_post_process(history=True)
- obj.save()
if (
not self.simulate
and self.import_instance