summaryrefslogtreecommitdiff
path: root/archaeological_context_records
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2020-11-17 15:37:22 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:21 +0100
commit53f899c9ded29921c982e67f220716b2f86823f3 (patch)
treee983fd246f6fd2ce0e9521ea23c1f93c73cc8bc9 /archaeological_context_records
parent9667957457eaf024e1b4a40f5d04ae001c4eeaca (diff)
downloadIshtar-53f899c9ded29921c982e67f220716b2f86823f3.tar.bz2
Ishtar-53f899c9ded29921c982e67f220716b2f86823f3.zip
Manage a "custom_index" for base types
Diffstat (limited to 'archaeological_context_records')
-rw-r--r--archaeological_context_records/migrations/0105_auto_20201117_0759.py25
-rw-r--r--archaeological_context_records/tests.py54
2 files changed, 79 insertions, 0 deletions
diff --git a/archaeological_context_records/migrations/0105_auto_20201117_0759.py b/archaeological_context_records/migrations/0105_auto_20201117_0759.py
new file mode 100644
index 000000000..b51627b83
--- /dev/null
+++ b/archaeological_context_records/migrations/0105_auto_20201117_0759.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.27 on 2020-11-17 07:59
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_context_records', '0104_auto_20201104_0959'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='contextrecord',
+ name='custom_index',
+ field=models.IntegerField(blank=True, null=True, verbose_name='Custom index'),
+ ),
+ migrations.AddField(
+ model_name='historicalcontextrecord',
+ name='custom_index',
+ field=models.IntegerField(blank=True, null=True, verbose_name='Custom index'),
+ ),
+ ]
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index cd547bc07..6c2c256a0 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -488,6 +488,60 @@ class ContextRecordTest(ContextRecordInit, TestCase):
obj.fix()
self.assertEqual(obj.datings.count(), 2)
+ def test_custom_index(self):
+ profile, created = IshtarSiteProfile.objects.get_or_create(
+ slug='default', active=True)
+
+ # key: operation
+ profile.contextrecord_custom_index = 'operation_id'
+ profile.save()
+ cr1 = self.context_records[0]
+ cr1.save()
+ cr1 = models.ContextRecord.objects.get(pk=cr1.pk)
+ self.assertEqual(cr1.custom_index, 1)
+ cr2 = self.context_records[1]
+ cr2.operation = cr1.operation
+ cr2.save()
+ cr2 = models.ContextRecord.objects.get(pk=cr2.pk)
+ self.assertEqual(cr2.custom_index, 2)
+ ope = self.create_operation()[-1]
+ cr3 = self.create_context_record(
+ data={"operation": ope})[-1]
+ cr3 = models.ContextRecord.objects.get(pk=cr3.pk)
+ self.assertEqual(cr3.custom_index, 1)
+
+ # key: operation, unit
+ profile.contextrecord_custom_index = 'unit_id;operation_id'
+ profile.save()
+
+ su = models.Unit.objects.get(txt_idx='stratigraphic-unit')
+ dest = models.Unit.objects.get(txt_idx='sector')
+ cr1.unit, cr2.unit = su, dest
+ cr1.save()
+ cr2.save()
+ cr2 = models.ContextRecord.objects.get(pk=cr2.pk)
+ # no change if custom_index not reinit
+ self.assertEqual(cr2.custom_index, 2)
+ cr1 = models.ContextRecord.objects.get(pk=cr1.pk)
+ self.assertEqual(cr1.custom_index, 1)
+ cr2.custom_index = None
+ cr2.save()
+ cr2 = models.ContextRecord.objects.get(pk=cr2.pk)
+ # different unit -> 1
+ self.assertEqual(cr2.custom_index, 1)
+ cr2.unit = cr1.unit
+ cr2.custom_index = None
+ cr2.save()
+ cr2 = models.ContextRecord.objects.get(pk=cr2.pk)
+ # same unit and operation -> 2
+ self.assertEqual(cr2.custom_index, 2)
+ cr3.unit = cr1.unit
+ cr3.custom_index = None
+ cr3.save()
+ cr3 = models.ContextRecord.objects.get(pk=cr3.pk)
+ # same unit and other operation -> 1
+ self.assertEqual(cr3.custom_index, 1)
+
class ContextRecordSearchTest(ContextRecordInit, TestCase, SearchText):
fixtures = CONTEXT_RECORD_TOWNS_FIXTURES