diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-02-07 11:29:57 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:21:00 +0100 |
commit | 641830616108b3f6e7210600a3b0a0f9f1a227a9 (patch) | |
tree | f4b6674a743ce1b66dc93284f1521a7fcae8fa68 | |
parent | 1ddb738376757581fc8ae4bb8207656953176a92 (diff) | |
download | Ishtar-641830616108b3f6e7210600a3b0a0f9f1a227a9.tar.bz2 Ishtar-641830616108b3f6e7210600a3b0a0f9f1a227a9.zip |
Operation - Parcels - Modify: fix parcel deletion
-rw-r--r-- | archaeological_operations/forms.py | 6 | ||||
-rw-r--r-- | archaeological_operations/views.py | 11 |
2 files changed, 12 insertions, 5 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 18a83f033..4034b94cd 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -116,12 +116,14 @@ class ParcelForm(IshtarForm): return if not self.cleaned_data or (DELETION_FIELD_NAME in self.cleaned_data and self.cleaned_data[DELETION_FIELD_NAME]): - print("Youpitralala") return if (not self.cleaned_data.get('parcel_number') or not self.cleaned_data.get('section')) and \ not self.cleaned_data.get('public_domain'): - return {} + # empty line reinit cleaned data + self.cleaned_data["year"] = None + self.cleaned_data["town"] = None + return self.cleaned_data if not self.cleaned_data.get('town'): raise forms.ValidationError(_("Town section is required.")) return self.cleaned_data diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 016a43560..f5d1c514f 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -452,7 +452,9 @@ def operation_modify_parcels(request, pk): post_data = formset.cleaned_data for data in post_data: - print(data) + if (not data.get('parcel_number') or not data.get('section')) and \ + not data.get('public_domain'): + continue current_parcel = None if data.get("pk"): try: @@ -464,8 +466,8 @@ def operation_modify_parcels(request, pk): not_deleted_or_associated = True for key, value in data.items(): - if key == "DELETE" and value == True: - parcel_associated_by_context_record = models.ContextRecord.objects.filter(parcel=current_parcel.pk).all() + if key == "DELETE" and value is True: + parcel_associated_by_context_record = ContextRecord.objects.filter(parcel=current_parcel.pk).all() if parcel_associated_by_context_record.count() > 0: raise ValidationError("This parcel is associated with a context record. It can't be deleted.") else: @@ -486,7 +488,10 @@ def operation_modify_parcels(request, pk): town = models.Town.objects.get(pk=int(data.get("town"))) ) operation.parcels.add(parcel_to_add) + return redirect(reverse("operation-parcels-modify", args=[pk])) else: + print(formset.errors) + print(formset.non_form_errors()) print("je passe ici") else: formset = formset_class(initial=initial, data=data) |