diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-02-05 17:19:07 +0100 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-02-09 16:54:41 +0100 |
| commit | abda76b788ad5f7474b75c8c2514386e416dcdf3 (patch) | |
| tree | 1f291cfa4f9e0fea425a3435866c88f5a5b3fe63 /ishtar_common | |
| parent | 1e5493a7a4e6eae87353ef2939efb1a5e2d4a5e0 (diff) | |
| download | Ishtar-abda76b788ad5f7474b75c8c2514386e416dcdf3.tar.bz2 Ishtar-abda76b788ad5f7474b75c8c2514386e416dcdf3.zip | |
🚑️ imports: fix concatenation of existing fields - fix concat string
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/data_importer.py | 50 | ||||
| -rw-r--r-- | ishtar_common/fixtures/initial_importtypes-tests-fr.json | 2 |
2 files changed, 25 insertions, 27 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index dc431adee..d1230219f 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1608,7 +1608,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): @@ -2185,42 +2185,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 244516a25..0123f7223 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", |
