diff options
-rw-r--r-- | CHANGES.md | 1 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 17 | ||||
-rw-r--r-- | ishtar_common/data_importer.py | 5 | ||||
-rw-r--r-- | ishtar_common/models_imports.py | 3 |
4 files changed, 24 insertions, 2 deletions
diff --git a/CHANGES.md b/CHANGES.md index 44b54fef4..2e3220ca7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ date: 2022-12-05 - Sheet: set default permissions to False - Find sheet: do not display container information if no permission - Image field: can use camera for mobile device +- Import value formater: can use {item} notation for format ### Bug fixes ### - Full text search: add "simple" config in search diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 36b96176a..a37a824d4 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -490,6 +490,23 @@ class ImportOperationTest(ImportTest, TestCase): ) f.delete() + f = ValueFormater.objects.create(name="-", slug="-", format_string="oa-{item}{item}") + column.value_format = f + column.save() + + self.assertTrue(form.is_valid()) + impt = form.save(self.ishtar_user) + impt.initialize() + self.init_ope_targetkey(imp=impt) + impt.importation() + self.assertEqual( + models.Operation.objects.filter(code_patriarche="oa-42014201").count(), 1 + ) + self.assertEqual( + models.Operation.objects.filter(code_patriarche="oa-42004200").count(), 1 + ) + f.delete() + def test_keys_limitation(self): # each key association associated to the import init_ope_number = models.Operation.objects.count() diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 8d99889fc..d63004849 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1665,7 +1665,10 @@ class Importer(object): c_values.append("") return if formater.value_format and value is not None and value != "": - value = formater.value_format.format(value) + if "{item" in formater.value_format: + value = formater.value_format.format(item=value) + else: + value = formater.value_format.format(value) if hasattr(value, "close"): # opened file are kept - they need to be listed and closed # later diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 46d92c994..b61d591b1 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -672,7 +672,8 @@ class ValueFormater(models.Model): "A string used to format a value using the Python " '"format()" method. The site https://pyformat.info/ ' 'provide good examples of usage. Only one "{}" entry ' - "is managed. The input is assumed to be a string." + 'is managed. Instead you can use "{item}". The input is ' + 'assumed to be a string.' ), ) objects = SlugModelManager() |