diff options
Diffstat (limited to 'archaeological_operations/views.py')
| -rw-r--r-- | archaeological_operations/views.py | 18 | 
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])      }) | 
