summaryrefslogtreecommitdiff
path: root/archaeological_operations/views.py
diff options
context:
space:
mode:
authorCefin <kevon@tuta.io>2022-02-01 16:36:40 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:21:00 +0100
commitc8c8b4f798315559dbc56d478daff57d002a3bd9 (patch)
tree0b29b802cfedec8d9fd900567e10eb2e1be51c55 /archaeological_operations/views.py
parent280eabb5e82195bb79ef08ae71a7bb1a2efaf06e (diff)
downloadIshtar-c8c8b4f798315559dbc56d478daff57d002a3bd9.tar.bz2
Ishtar-c8c8b4f798315559dbc56d478daff57d002a3bd9.zip
Operation - Parcels - Modify: change condition on ca relation and commit before using additionnal formset #5227
Diffstat (limited to 'archaeological_operations/views.py')
-rw-r--r--archaeological_operations/views.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index b6099d6b1..f7da19483 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -454,16 +454,19 @@ def operation_modify_parcels(request, pk):
current_parcel = models.Parcel.objects.get(pk=post_data["pk"])
if current_parcel:
- not_deleted = True
+ 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.get(parcel=current_parcel.pk)
- if parcel_associated_by_context_record:
- raise ValidationError("This parcel is associated with a context record. It can't be deleted.") #TOVERIFY
+ parcel_associated_by_context_record = models.ContextRecord.objects.filter(parcel=current_parcel.pk).all()
+ if len(parcel_associated_by_context_record) > 0:
+ raise ValidationError("This parcel is associated with a context record. It can't be deleted.")
+ not_deleted_or_associated = False
else:
current_parcel.delete()
- not_deleted = False
- if not_deleted:
+ not_deleted_or_associated = False
+
+ if not_deleted_or_associated:
current_parcel.year = post_data.get("year")
current_parcel.section = post_data.get("section")
current_parcel.parcel_number = post_data.get("parcel_number")
@@ -489,12 +492,15 @@ def operation_modify_parcels(request, pk):
})
formset = formset_class(initial=initial, data=data)
+ # formset = formset_class(initial=initial, data=data, prefix="modified_parcel")
+ # formset_add = formset_class(data=data, prefix="new_parcel")
for form in formset:# DEBUG
print(form.as_table())# DEBUG
return render(request, 'ishtar/forms/operation_modify_parcels.html', {
'formset': formset,
+ 'formset_add': formset_add,
"url": reverse("operation-parcels-modify", args=[pk])
})