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/models.py | |
parent | 20d5c7d28d127a2ef8deab2ba2c6a7045700b6c8 (diff) | |
download | Ishtar-e199d50cd6430597f303d0d8cc876ce8a55801a7.tar.bz2 Ishtar-e199d50cd6430597f303d0d8cc876ce8a55801a7.zip |
Import: manage pre-import function - test document import
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 24 |
1 files changed, 17 insertions, 7 deletions
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 \ |