diff options
| -rw-r--r-- | archaeological_context_records/models.py | 7 | ||||
| -rw-r--r-- | archaeological_context_records/tests.py | 48 | ||||
| -rw-r--r-- | archaeological_finds/models_finds.py | 7 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 2 | 
4 files changed, 58 insertions, 6 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 490124342..4084ec05a 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -159,7 +159,7 @@ class CRBulkView(object):  class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, -                      ValueGetter, ShortMenuItem): +                    ValueGetter, ShortMenuItem):      SHOW_URL = 'show-contextrecord'      SLUG = 'contextrecord'      TABLE_COLS = ['label', 'operation__common_name', 'parcel__town__name', @@ -403,8 +403,9 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,          return self.full_label()      def _get_associated_cached_labels(self): -        from archaeological_finds.models import Find -        return list(Find.objects.filter(base_finds__context_record=self).all()) +        from archaeological_finds.models import Find, BaseFind +        return list(Find.objects.filter(base_finds__context_record=self).all())\ +            + list(BaseFind.objects.filter(context_record=self).all())      @property      def reference(self): diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 6bb293e4d..14a5ae8d3 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -235,7 +235,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):          models.RecordRelations.objects.create(              left_record=cr_1, right_record=cr_2, relation_type=sym_rel_type) -    def testExternalID(self): +    def test_external_id(self):          cr = self.context_records[0]          self.assertEqual(              cr.external_id, @@ -255,7 +255,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):              cr.operation          ) -    def test_cache_update(self): +    def test_upstream_cache_update(self):          cr = self.create_context_record()[0]          cr_pk = cr.pk          # OP2010 - 1 | A | 1 | CR 1 @@ -288,6 +288,50 @@ class ContextRecordTest(ContextRecordInit, TestCase):          ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')          self.assertEqual(ope_id, 'OP2017-1') +    def test_downstream_cache_update(self): +        cr = self.create_context_record()[0] + +        from archaeological_finds.models import Find, BaseFind, MaterialType + +        data = { +            'label': "Find me a reason", +            'context_record': cr, +            'history_modifier': self.get_default_user() +        } +        bf = BaseFind.objects.create(**data) +        find = Find.objects.create( +            history_modifier=self.get_default_user(), +            label='Find me too' +        ) +        find.base_finds.add(bf) + +        mat = MaterialType.objects.create( +            label='Adamentium', txt_idx='admentium', code='ADA') +        find.material_types.add(mat) + +        class TestObj(object): +            def __init__(self): +                self.find_reached = [] + +            def reached(self, sender, **kwargs): +                instance = kwargs.get('instance') +                if sender == Find: +                    self.find_reached.append(instance) + +        test_obj = TestObj() +        cr = models.ContextRecord.objects.get(pk=cr.pk) +        cr.test_obj = test_obj +        cr.label = "New label!" +        cr.save() + +        # verify the relevance of the update +        bf = BaseFind.objects.get(pk=bf.pk) +        self.assertIn("New label!", bf.cache_complete_id) + +        # bulk update of find cached label gen don't have to be +        # reached +        self.assertEqual(len(test_obj.find_reached), 0) +  class ContextRecordSearchTest(ContextRecordInit, TestCase):      fixtures = ImportContextRecordTest.fixtures diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 1b492148a..68bc5269c 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -192,6 +192,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms):          help_text=_(u"Cached value - do not edit"))      history = HistoricalRecords()      RELATED_POST_PROCESS = ['find'] +    CACHED_LABELS = ['cache_short_id', 'cache_complete_id']      class Meta:          verbose_name = _(u"Base find") @@ -254,6 +255,9 @@ class BaseFind(BaseHistorizedItem, OwnPerms):                       ).format(self.index))          return settings.JOINT.join(c_id) +    def _generate_cache_complete_id(self): +        return self.complete_id() +      def short_id(self):          # OPE|FIND_index          c_id = [self._ope_code()] @@ -261,6 +265,9 @@ class BaseFind(BaseHistorizedItem, OwnPerms):                       ).format(self.index))          return settings.JOINT.join(c_id) +    def _generate_cache_short_id(self): +        return self.short_id() +      def full_label(self):          return self._real_label() or self._temp_label() or u"" diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index e1ae68237..67f9454fa 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2012-2016 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-2017 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet>  # This program is free software: you can redistribute it and/or modify  # it under the terms of the GNU Affero General Public License as | 
