summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-04-04 12:13:04 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-04-04 12:13:04 +0200
commita0ef455fb3b477fbf03d9e8beee4bf7f122451d6 (patch)
tree6186b05eadafc75d6e2e184ea7cfcaa066e7bd1b
parentf6058532b7644c586d28eeeaf8b9308320f9fe19 (diff)
downloadIshtar-a0ef455fb3b477fbf03d9e8beee4bf7f122451d6.tar.bz2
Ishtar-a0ef455fb3b477fbf03d9e8beee4bf7f122451d6.zip
Base finds: bulk update of finds on context record change (refs #3484)
-rw-r--r--archaeological_context_records/models.py7
-rw-r--r--archaeological_context_records/tests.py6
-rw-r--r--archaeological_finds/models_finds.py20
3 files changed, 30 insertions, 3 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 4084ec05a..bb3afc899 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -407,6 +407,13 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
return list(Find.objects.filter(base_finds__context_record=self).all())\
+ list(BaseFind.objects.filter(context_record=self).all())
+ def _cached_labels_bulk_update(self):
+ if settings.TESTING and settings.USE_SPATIALITE_FOR_TESTS:
+ return
+ self.base_finds.model.cached_label_bulk_update(
+ context_record_id=self.pk)
+ return True
+
@property
def reference(self):
if not self.operation:
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 14a5ae8d3..4226b42ea 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -289,6 +289,10 @@ class ContextRecordTest(ContextRecordInit, TestCase):
self.assertEqual(ope_id, 'OP2017-1')
def test_downstream_cache_update(self):
+ if settings.USE_SPATIALITE_FOR_TESTS:
+ # using views - can only be tested with postgresql
+ return
+
cr = self.create_context_record()[0]
from archaeological_finds.models import Find, BaseFind, MaterialType
@@ -315,7 +319,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):
def reached(self, sender, **kwargs):
instance = kwargs.get('instance')
- if sender == Find:
+ if sender in (Find, BaseFind):
self.find_reached.append(instance)
test_obj = TestObj()
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 68bc5269c..3e14aa592 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -330,7 +330,8 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
return returned
@classmethod
- def cached_label_bulk_update(cls, operation_id=None, parcel_id=None):
+ def cached_label_bulk_update(cls, operation_id=None, parcel_id=None,
+ context_record_id=None):
if operation_id:
filters = """
INNER JOIN archaeological_context_records_contextrecord acr
@@ -345,6 +346,12 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
"""
args = [int(parcel_id)]
kwargs = {'parcel_id': parcel_id}
+ elif context_record_id:
+ filters = """
+ WHERE mybf.context_record_id = %s
+ """
+ args = [int(context_record_id)]
+ kwargs = {'context_record_id': context_record_id}
else:
return
@@ -905,7 +912,8 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
return unicode(self)
@classmethod
- def cached_label_bulk_update(cls, operation_id=None, parcel_id=None):
+ def cached_label_bulk_update(cls, operation_id=None, parcel_id=None,
+ context_record_id=None):
if operation_id:
filters = """
INNER JOIN find_first_base_find myfbf
@@ -926,6 +934,14 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
ON acr.parcel_id = %s AND acr.id = mybf.context_record_id
"""
args = [int(parcel_id)]
+ elif context_record_id:
+ filters = """
+ INNER JOIN find_first_base_find myfbf
+ ON myfbf.find_id = myf.id
+ INNER JOIN archaeological_finds_basefind mybf
+ ON myfbf.basefind_id = mybf.id AND mybf.context_record_id = %s
+ """
+ args = [int(parcel_id)]
else:
return