summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-06-09 15:54:37 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-06-09 15:54:37 +0200
commit0b185abf1079727568d44ed2568e52bc3a52752c (patch)
tree5425af50059702a998a0772b04e56b261cec96c5
parent42609e5c75728b1d98e3ef170120ffe0bceff0a5 (diff)
downloadIshtar-0b185abf1079727568d44ed2568e52bc3a52752c.tar.bz2
Ishtar-0b185abf1079727568d44ed2568e52bc3a52752c.zip
custom index: "whole_db" key is available for index on the whole db
-rw-r--r--CHANGES.md5
-rw-r--r--ishtar_common/models_common.py8
-rw-r--r--ishtar_common/tests.py17
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"