From f9620956381f843fc5d341fd19cdf0fc0f68d1a7 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 11 Mar 2019 20:05:04 +0100 Subject: Import: manage pre-import function - test document import --- ishtar_common/models.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'ishtar_common/models.py') 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 \ -- cgit v1.2.3