diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-11 20:05:04 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:41:37 +0200 |
commit | e199d50cd6430597f303d0d8cc876ce8a55801a7 (patch) | |
tree | d4dd0e61a429a660c7ec8776bf9287dab8d5610f /ishtar_common | |
parent | 20d5c7d28d127a2ef8deab2ba2c6a7045700b6c8 (diff) | |
download | Ishtar-e199d50cd6430597f303d0d8cc876ce8a55801a7.tar.bz2 Ishtar-e199d50cd6430597f303d0d8cc876ce8a55801a7.zip |
Import: manage pre-import function - test document import
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/data_importer.py | 2 | ||||
-rw-r--r-- | ishtar_common/models.py | 24 | ||||
-rw-r--r-- | ishtar_common/tests.py | 2 |
3 files changed, 19 insertions, 9 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index d20096a91..d4c4ba786 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1542,7 +1542,7 @@ class Importer(object): """ func = getattr(cls, attribute) if func.importer_trigger == 'pre': - pass # TODO + func(data, data[attribute]) elif func.importer_trigger == 'post': self._item_post_processing.append([attribute, data, data[attribute]]) diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 641a9b0a4..57283e8f4 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -70,6 +70,8 @@ from unidecode import unidecode from ishtar_common.alternative_configs import ALTERNATE_CONFIGS, \ ALTERNATE_CONFIGS_CHOICES +from ishtar_common.data_importer import pre_importer_action + from ishtar_common.model_merging import merge_model_objects from ishtar_common.models_imports import ImporterModel, ImporterType, \ ImporterDefault, ImporterDefaultValues, ImporterColumn, \ @@ -4690,18 +4692,26 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel): def _generate_cache_related_label(self): return self.related_label() - def set_index(self): - if self.index: - return - q = Document.objects.values('index').filter( + @classmethod + def get_next_index(cls): + q = cls.objects.values('index').filter( index__isnull=False).order_by("-index") if not q.count(): - self.index = 1 - return + return 1 cid = q.all()[0]['index'] if not cid: cid = 0 - self.index = cid + 1 + return cid + 1 + + def set_index(self): + if self.index: + return + self.index = self.get_next_index() + + @classmethod + @pre_importer_action + def import_get_next_index(cls, context, value): + context["index"] = cls.get_next_index() def save(self, *args, **kwargs): no_path_change = 'no_path_change' in kwargs \ diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 3e9181f30..7166f9cb7 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1360,7 +1360,7 @@ class ShortMenuTest(TestCase): class ImportTest(TestCase): - def testDeleteRelated(self): + def test_delete_related(self): town = models.Town.objects.create(name='my-test') self.assertEqual(models.Town.objects.filter(name='my-test').count(), 1) |