diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-05-28 11:31:04 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:28 +0200 |
commit | 096bf9a3dcee0d72dba4c6c9f3802a02ac6d4d12 (patch) | |
tree | e19f1dfa26f4547001189721a89f0a5cbe036c57 /archaeological_context_records | |
parent | 7587c316830be2c2866b2feeec4b44d081847338 (diff) | |
download | Ishtar-096bf9a3dcee0d72dba4c6c9f3802a02ac6d4d12.tar.bz2 Ishtar-096bf9a3dcee0d72dba4c6c9f3802a02ac6d4d12.zip |
Fix cache generation for finds and context records
Diffstat (limited to 'archaeological_context_records')
-rw-r--r-- | archaeological_context_records/migrations/0046_auto_20190528_1048.py | 25 | ||||
-rw-r--r-- | archaeological_context_records/models.py | 20 | ||||
-rw-r--r-- | archaeological_context_records/tests.py | 2 |
3 files changed, 41 insertions, 6 deletions
diff --git a/archaeological_context_records/migrations/0046_auto_20190528_1048.py b/archaeological_context_records/migrations/0046_auto_20190528_1048.py new file mode 100644 index 000000000..f00f2a184 --- /dev/null +++ b/archaeological_context_records/migrations/0046_auto_20190528_1048.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-05-28 10:48 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_context_records', '0045_auto_20190527_1645'), + ] + + operations = [ + migrations.AddField( + model_name='contextrecord', + name='cached_related_context_records', + field=models.TextField(blank=True, help_text='Generated automatically - do not edit', null=True, verbose_name='Cached related context records'), + ), + migrations.AddField( + model_name='historicalcontextrecord', + name='cached_related_context_records', + field=models.TextField(blank=True, help_text='Generated automatically - do not edit', null=True, verbose_name='Cached related context records'), + ), + ] diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 1b63af51a..ace66aed6 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -293,7 +293,8 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, 'cached_periods': _("Periods"), 'datings__period__label': _("Periods"), 'datings__period': _("Datings (period)"), - 'detailled_related_context_records': _("Related context records"), + 'detailed_related_context_records': _("Related context records"), + "cached_related_context_records": _("Related context records"), 'operation__code_patriarche': _("Operation (Patriarche code)"), 'operation__common_name': _("Operation (name)"), 'parcel__external_id': _("Parcel (external ID)"), @@ -302,10 +303,11 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, 'parcel__year': _("Parcel (year)"), 'section__parcel_number': _("Parcel"), 'parcel__cached_label': _("Parcel"), + 'unit__label': _("Context record type"), } CONTEXTUAL_TABLE_COLS = { 'full': { - 'related_context_records': 'detailled_related_context_records' + 'related_context_records': 'cached_related_context_records' } } # statistics @@ -427,7 +429,8 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, HISTORICAL_M2M = [ 'datings', 'documentations' ] - CACHED_LABELS = ['cached_label', 'cached_periods'] + CACHED_LABELS = ['cached_label', 'cached_periods', + "cached_related_context_records"] history = HistoricalRecords(bases=[HistoryModel]) objects = ExternalIdManager() @@ -516,6 +519,10 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, _("Cached periods label"), blank=True, null=True, help_text=_("Generated automatically - do not edit") ) + cached_related_context_records = models.TextField( + _("Cached related context records"), blank=True, null=True, + help_text=_("Generated automatically - do not edit") + ) class Meta: verbose_name = _("Context Record") @@ -716,6 +723,9 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, return " & ".join([dating.period.label for dating in self.datings.all()]) + def _generate_cached_related_context_records(self): + return self.detailed_related_context_records() + def _get_associated_cached_labels(self): from archaeological_finds.models import Find, BaseFind return list(Find.objects.filter(base_finds__context_record=self).all())\ @@ -793,12 +803,12 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, q = q.filter(**fltr) return q.count() - def detailled_related_context_records(self): + def detailed_related_context_records(self): crs = [] for cr in self.right_relations.all(): crs.append("{} ({})".format(cr.right_record, cr.relation_type.get_tiny_label())) - return " ; ".join(crs) + return " & ".join(crs) def find_docs_q(self): return Document.objects.filter(finds__base_finds__context_record=self) diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 764750cf6..79d60bf09 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -568,7 +568,7 @@ class ContextRecordSearchTest(ContextRecordInit, TestCase): self.assertEqual(response.status_code, 200) res = json.loads(response.content.decode()) self.assertEqual(res['recordsTotal'], 1) - self.assertEqual(res["rows"][0]["unit"], str(neg)) + self.assertEqual(res["rows"][0]["unit__label"], str(neg)) # no result for the brother search = {'unit': dest.pk} |