diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-22 16:00:17 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-22 16:00:17 +0100 |
commit | 146901b482bff1c735b6fe256e29c55740e17875 (patch) | |
tree | f8e68b974ce763b15fa00150a71d1ad5a10504e8 | |
parent | b564d3d2d32782ca439f9d721d01b0fe6cff25a3 (diff) | |
download | Ishtar-146901b482bff1c735b6fe256e29c55740e17875.tar.bz2 Ishtar-146901b482bff1c735b6fe256e29c55740e17875.zip |
Update context record label on parcel change
-rw-r--r-- | archaeological_context_records/tests.py | 1 | ||||
-rw-r--r-- | archaeological_operations/models.py | 7 |
2 files changed, 6 insertions, 2 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index b87f3ce4d..4f0594698 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -204,6 +204,7 @@ class ContextRecordTest(ContextRecordInit, TestCase): parcel = models.Parcel.objects.get(pk=cr.parcel.pk) parcel.operation = None parcel.save() + # associated context record is not removed self.assertEqual( models.ContextRecord.objects.filter(pk=cr.pk).count(), 1) # associated operation is restored diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 225d46a53..707537fe3 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1357,7 +1357,6 @@ class Parcel(LightHistorizedItem): def parcel_post_save(sender, **kwargs): if not kwargs['instance']: return - from archaeological_context_records.models import ContextRecord parcel = kwargs['instance'] created = kwargs.get('created', None) @@ -1377,13 +1376,17 @@ def parcel_post_save(sender, **kwargs): external_id = get_external_id('parcel_external_id', parcel) if external_id != parcel.external_id: updated = True + parcel._updated_id = True parcel.auto_external_id = True parcel.external_id = external_id if updated: - parcel._updated_id = True parcel.save() return + if parcel.context_record.count(): + for cr in parcel.context_record.all(): + cached_label_changed(cr.__class__, instance=cr) + if parcel.operation and parcel.operation.pk and \ parcel.town not in list(parcel.operation.towns.all()): parcel.operation.towns.add(parcel.town) |