diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-01 12:41:44 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:03 +0200 |
commit | 2217e20855027c8233f98f6249dfb843f7dfb54c (patch) | |
tree | 34a471d9e263947fdfc6e6f1c2287f2fd3cb411a /archaeological_operations | |
parent | de2020b06facad52aae63140d0b6155aa5b72d0a (diff) | |
download | Ishtar-2217e20855027c8233f98f6249dfb843f7dfb54c.tar.bz2 Ishtar-2217e20855027c8233f98f6249dfb843f7dfb54c.zip |
Fix innapropriate parcel deletion
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/forms.py | 28 | ||||
-rw-r--r-- | archaeological_operations/models.py | 12 |
2 files changed, 24 insertions, 16 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index acce3835b..866700871 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -77,20 +77,6 @@ class ParcelForm(IshtarForm): public_domain = forms.BooleanField(label=_(u"Public domain"), initial=False, required=False) - def count_valid_fields(self, data): - if not data: - return 0 - data = get_data_from_formset(data) - nb = len(data) - # remove last non relevant fields - for idx, vals in enumerate(reversed(data[:])): - if 'public_domain' in vals: - break - if 'section' in vals and 'parcel_number' in vals: - break - nb -= 1 - return nb - def __init__(self, *args, **kwargs): towns = None if 'data' in kwargs and 'TOWNS' in kwargs['data']: @@ -106,6 +92,20 @@ class ParcelForm(IshtarForm): if towns: self.fields['town'].choices = towns + def count_valid_fields(self, data): + if not data: + return 0 + data = get_data_from_formset(data) + nb = len(data) + # remove last non relevant fields + for idx, vals in enumerate(reversed(data[:])): + if 'public_domain' in vals: + break + if 'section' in vals and 'parcel_number' in vals: + break + nb -= 1 + return nb + def clean(self): """Check required fields""" if any(self.errors): diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 1c3bbde99..1a534af7a 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1395,6 +1395,8 @@ def strip_zero(value): class Parcel(LightHistorizedItem): EXTERNAL_ID_KEY = 'parcel_external_id' + BASE_SEARCH_VECTORS = ['section', 'parcel_number'] + PARENT_SEARCH_VECTORS = ['operation'] associated_file = models.ForeignKey( 'archaeological_files.File', @@ -1569,21 +1571,27 @@ def parcel_post_save(sender, **kwargs): if not kwargs['instance']: return parcel = kwargs['instance'] - created = kwargs.get('created', None) cached_label_changed(sender, **kwargs) updated = False + + """ # remove when the parcel is linked to nothing + # problematic in wizards + # TODO: add admin action if not getattr(parcel, '_updated_id', None) and not created \ and not parcel.operation and not parcel.associated_file: if parcel.context_record.count(): # trying to restore a lost parcel parcel.operation = parcel.context_record.all()[0].operation updated = True - else: + elif parcel.id: parcel.delete() return + else: + return + """ if updated: parcel.save() |