diff options
author | Cefin <kevon@tuta.io> | 2022-01-31 15:29:25 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:21:00 +0100 |
commit | f14c72ff4ed319ba26f9e7111eac7a01f959359e (patch) | |
tree | 6db9d6c2d7c3e2c5138add38c293ae4af1fade6f | |
parent | 0f3baa049c81e336457d529542e439b0d6c4827d (diff) | |
download | Ishtar-f14c72ff4ed319ba26f9e7111eac7a01f959359e.tar.bz2 Ishtar-f14c72ff4ed319ba26f9e7111eac7a01f959359e.zip |
Operation - Parcels - Modify: Adding validation error on association on ca #5227
-rw-r--r-- | archaeological_operations/views.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index dc03f0641..2a8207375 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -417,16 +417,18 @@ def operation_modify_parcels(request, pk): available_towns = [] for town in operation.towns.all(): - available_towns.append((town.id, town.name)) + available_towns.append((town.pk, str(town))) + if request.method == 'POST': - formset = formset_class(request.POST, request.FILES) - print(formset.non_form_errors()) - for form in formset: - print(form.errors) + + data = {'TOWNS': available_towns} + formset = formset_class(request.POST, request.FILES, data=data) #DON'T WORK THAT WAY + for form in formset: #DEBUG + print(form.errors) #DEBUG + if formset.is_valid(): - print(formset.non_form_errors()) - print(formset.cleaned_data) + print(formset.cleaned_data) #DEBUG post_data = [form.cleaned_data for form in formset] for data in post_data: current_parcel = models.Parcel.objects.get(pk=post_data.get("pk")) @@ -435,8 +437,12 @@ def operation_modify_parcels(request, pk): not_deleted = True for key, value in data.items(): if key == "DELETE" and value == True: - current_parcel.delete() - not_deleted = False + 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 + else: + current_parcel.delete() + not_deleted = False if not_deleted: current_parcel.year = post_data.get("year") current_parcel.section = post_data.get("section") @@ -458,7 +464,7 @@ def operation_modify_parcels(request, pk): initial = [] if parcels: for parcel in parcels: - town = models.Town.objects.get(pk=parcel.town_id) + town = models.Town.objects.get(pk=int(parcel.town_id)) initial.append({ "pk": parcel.pk, "town": town, |