diff options
| -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 | ||||
| -rw-r--r-- | archaeological_finds/models_finds.py | 16 | ||||
| -rw-r--r-- | archaeological_finds/tests.py | 4 | ||||
| -rw-r--r-- | ishtar_common/views_item.py | 2 | 
6 files changed, 58 insertions, 11 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} diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 69d9e92bf..ad9e2a822 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1572,15 +1572,15 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem,          help_text=_(u"Related treatments when no new find is created"))      cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,                                      db_index=True) -    cached_periods =  models.TextField( +    cached_periods = models.TextField(          _("Cached periods label"), blank=True, null=True,          help_text=_("Generated automatically - do not edit")      ) -    cached_object_types =  models.TextField( +    cached_object_types = models.TextField(          _("Cached object types label"), blank=True, null=True,          help_text=_("Generated automatically - do not edit")      ) -    cached_materials =  models.TextField( +    cached_materials = models.TextField(          _("Cached material types label"), blank=True, null=True,          help_text=_("Generated automatically - do not edit")      ) @@ -1953,6 +1953,16 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem,          return Find.objects.filter(pk=self.pk).values(              'cached_label')[0]['cached_label'] +    def _generate_cached_periods(self): +        return " & ".join([dating.period.label +                           for dating in self.datings.all()]) + +    def _generate_cached_object_types(self): +        return " & ".join([str(obj) for obj in self.object_types.all()]) + +    def _generate_cached_materials(self): +        return " & ".join([str(mat) for mat in self.material_types.all()]) +      @classmethod      def cached_label_bulk_update(              cls, operation_id=None, parcel_id=None, context_record_id=None, diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 620f648fd..d5f1fdb62 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -680,7 +680,7 @@ class FindSearchTest(FindInit, TestCase):          content = response.content.decode()          res = json.loads(content)          self.assertEqual(res['recordsTotal'], 1) -        self.assertEqual(res["rows"][0]["material_types__label"], +        self.assertEqual(res["rows"][0]["material_types"],                           str(iron_metal))          # no result for the brother @@ -744,7 +744,7 @@ class FindSearchTest(FindInit, TestCase):          self.assertEqual(response.status_code, 200)          res = json.loads(response.content.decode())          self.assertEqual(res['recordsTotal'], 1) -        self.assertEqual(res["rows"][0]["datings__period__label"], +        self.assertEqual(res["rows"][0]["cached_periods"],                           str(final_neo))          # no result for the brother diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 032d3e2c2..c508fa35d 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1864,6 +1864,8 @@ def get_item(model, func_name, default_name, extra_request_keys=None,                          if isinstance(value, datetime.datetime):                              value = value.strftime('%Y-%m-%d %H:%M:%S')                          res[k] = value +                    else: +                        res[k] = ""                  if full == 'shortcut':                      if 'cached_label' in res:                          res['value'] = res.pop('cached_label') | 
