diff options
-rw-r--r-- | CHANGES.md | 5 | ||||
-rw-r--r-- | ishtar_common/models_common.py | 8 | ||||
-rw-r--r-- | ishtar_common/tests.py | 17 |
3 files changed, 30 insertions, 0 deletions
diff --git a/CHANGES.md b/CHANGES.md index e9dda6ecc..57ea00970 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,11 @@ date: 2022-06-08 Ishtar changelog ================ +### Features ### + +- custom index: "whole_db" key is available for index on the whole db + + v3.1.74 - 2022-06-08 -------------------- diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index fd1a00d95..ac42e5ee6 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -3021,6 +3021,14 @@ class CompleteIdentifierItem(models.Model, ImageContainerModel): complete_identifier = getattr(self, cached_label_key) return complete_identifier + def get_index_whole_db(self): + q = self.__class__.objects.exclude(custom_index__isnull=True) + q = q.order_by("-custom_index") + if q.count(): + current_index = q.values_list("custom_index", flat=True).all()[0] + return current_index + 1 + return 1 + def generate_custom_index(self, force=False): if not self.pk: return diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index bd37226ff..7ec38913a 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -3062,6 +3062,23 @@ class DocumentTest(TestCase): doc3 = models.Document.objects.get(pk=doc3.pk) self.assertEqual(doc3.complete_identifier, "no-code") + profile.document_custom_index = "whole_db" + profile.save() + + models.Document.objects.update(custom_index=None) + doc = models.Document.objects.get(pk=doc.pk) + doc2 = models.Document.objects.get(pk=doc2.pk) + doc3 = models.Document.objects.get(pk=doc3.pk) + doc.save() + doc3.save() + doc2.save() + doc = models.Document.objects.get(pk=doc.pk) + self.assertEqual(doc.custom_index, 1) + doc3 = models.Document.objects.get(pk=doc3.pk) + self.assertEqual(doc3.custom_index, 2) + doc2 = models.Document.objects.get(pk=doc2.pk) + self.assertEqual(doc2.custom_index, 3) + def test_clean_duplicate_association(self): doc = models.Document.objects.create( source_type=self.st1, title="Operation report" |