From 014ae7758af5c5dbd75c7ccbcbf6f203c40c85e1 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 2 Dec 2020 13:05:11 +0100 Subject: Archaeological files: fix parcel clean on save --- archaeological_operations/models.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'archaeological_operations') diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 368b2e33c..d0de32be2 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -682,9 +682,23 @@ class ClosedItem(object): return {'date': date, 'user': user} +class ParcelItem: + def clean_parcel_duplicates(self): + parcels = [] + for p in self.parcels.order_by('pk').all(): + if p.associated_file: + continue + key = (p.section, p.parcel_number, p.year, p.town.pk, + p.public_domain) + if key in parcels: + p.delete() + else: + parcels.append(key) + + class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, GeoItem, OwnPerms, ValueGetter, MainItem, - DashboardFormItem, RelationItem): + DashboardFormItem, RelationItem, ParcelItem): SLUG = 'operation' APP = "archaeological-operations" MODEL = "operation" @@ -1739,18 +1753,6 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, res['mode'] = " ; ".join([str(m) for m in mode(finds)]) return res - def clean_parcel_duplicates(self): - parcels = [] - for p in self.parcels.order_by('pk').all(): - if p.associated_file: - continue - key = (p.section, p.parcel_number, p.year, p.town.pk, - p.public_domain) - if key in parcels: - p.delete() - else: - parcels.append(key) - def save(self, *args, **kwargs): # put a default year if start_date is defined if self.start_date and not self.year: -- cgit v1.2.3