summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2026-02-05 17:19:07 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2026-02-09 10:56:46 +0100
commitb0a9718a100365f8d3e541ac68fbf174a3aea9b4 (patch)
tree6105ab2c8fe94687f1c9f2b9ec638f36e8eee3ed /ishtar_common
parent3345a80dc9e0951022a10442407a1b09e8b24b6d (diff)
downloadIshtar-b0a9718a100365f8d3e541ac68fbf174a3aea9b4.tar.bz2
Ishtar-b0a9718a100365f8d3e541ac68fbf174a3aea9b4.zip
🚑️ imports: fix concatenation of existing fields - fix concat string
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/data_importer.py50
-rw-r--r--ishtar_common/fixtures/initial_importtypes-tests-fr.json2
2 files changed, 25 insertions, 27 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index d9d7a4bac..7287fc058 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -1575,7 +1575,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):
@@ -2152,42 +2152,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
- elif "defaults" in dct:
- 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
diff --git a/ishtar_common/fixtures/initial_importtypes-tests-fr.json b/ishtar_common/fixtures/initial_importtypes-tests-fr.json
index e8bdb40f9..b0b156f83 100644
--- a/ishtar_common/fixtures/initial_importtypes-tests-fr.json
+++ b/ishtar_common/fixtures/initial_importtypes-tests-fr.json
@@ -1615,7 +1615,7 @@
"mcc-mobilier",
23
],
- "target": "base_finds__description",
+ "target": "description",
"formater_type": [
"UnicodeFormater",
"1000",