diff options
| -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, | 
