diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/models.py | 16 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 45 |
2 files changed, 56 insertions, 5 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 707537fe3..1f65b4c1f 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -431,13 +431,13 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, def get_reference(self, full=False): ref = "" if settings.COUNTRY == 'fr' and self.code_patriarche: - ref = "OA" + unicode(self.code_patriarche) + ref = settings.ISHTAR_OPE_PREFIX + unicode(self.code_patriarche) if not full: return ref if self.year and self.operation_code: if ref: ref += u" - " - ref += settings.OP_PREFIX + ref += settings.ISHTAR_DEF_OPE_PREFIX ref += u"-".join((unicode(self.year), unicode(self.operation_code))) return ref or "00" @@ -463,6 +463,12 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, def _get_associated_cached_labels(self): return list(self.context_record.all()) + def _cached_labels_bulk_update(self): + if settings.USE_SPATIALITE_FOR_TESTS: + return + self.context_record.model.cached_label_bulk_update(operation_id=self.pk) + return True + def get_town_label(self): lbl = unicode(_('Intercommunal')) if self.towns.count() == 1: @@ -518,15 +524,15 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, return "" lbl = unicode(self.operation_code) year = self.year or 0 - lbl = settings.OP_PREFIX + u"%d-%s%s" % (year, (3 - len(lbl)) * "0", - lbl) + lbl = settings.ISHTAR_DEF_OPE_PREFIX \ + + u"%d-%s%s" % (year, (3 - len(lbl)) * "0", lbl) return lbl @property def full_code_patriarche(self): if not self.code_patriarche: return '' - return u"OA" + unicode(self.code_patriarche) + return settings.ISHTAR_OPE_PREFIX + unicode(self.code_patriarche) def clean(self): if not self.operation_code: diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index a9fdf38cc..f0d07c33c 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -768,6 +768,51 @@ class OperationTest(TestCase, OperationInitTest): self.assertEqual(ope_id, 'OP2011-1') self.assertEqual(town, self.towns[0].name) + def test_cache_bulk_update(self): + if settings.USE_SPATIALITE_FOR_TESTS: + # using views can only be tested with postgresql + return + + operation = self.operations[0] + init_parcel = self.create_parcel()[0] + operation.parcels.add(init_parcel) + + from archaeological_context_records.models import ContextRecord + cr_data = {'label': "Context record", "operation": operation, + 'parcel': init_parcel, + 'history_modifier': self.get_default_user()} + cr = ContextRecord.objects.create(**cr_data) + + class TestObj(object): + def __init__(self): + self.context_record_reached = [] + + def reached(self, sender, **kwargs): + instance = kwargs.get('instance') + if sender == ContextRecord: + self.context_record_reached.append(instance) + + test_obj = TestObj() + operation = models.Operation.objects.get(pk=operation.pk) + operation.test_obj = test_obj + operation.year = 2011 + operation.save() + # bulk update of context records cached label gen don't have to be + # reached + self.assertEqual(len(test_obj.context_record_reached), 0) + + # verify the relevance of the update + cr = ContextRecord.objects.get(pk=cr.pk) + ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ') + self.assertEqual(ope_id, '{}2011-1'.format( + settings.ISHTAR_DEF_OPE_PREFIX)) + + operation.code_patriarche = '666' + operation.save() + cr = ContextRecord.objects.get(pk=cr.pk) + ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ') + self.assertEqual(ope_id, '666'.format(settings.ISHTAR_OPE_PREFIX)) + class OperationSearchTest(TestCase, OperationInitTest): fixtures = [settings.ROOT_PATH + |
