diff options
-rw-r--r-- | archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html | 13 | ||||
-rw-r--r-- | archaeological_operations/views.py | 18 |
2 files changed, 24 insertions, 7 deletions
diff --git a/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html b/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html index 3a9f2785c..434ba9490 100644 --- a/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html +++ b/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html @@ -10,6 +10,7 @@ </div> <form enctype="multipart/form-data" action="{{url}}" method="post" id="qa-new-{{ formset.form_slug }}"> {{ formset.management_form }} + {{ formset_add.management_form }} {% csrf_token %} <div class="modal-body body-scroll"> <div class='form'> @@ -31,7 +32,17 @@ </td> </tr> </table> - + {% comment %} <h3>Add a new parcel</h3> {% endcomment %} + {% comment %} {% if formset_add.non_form_errors %} {% endcomment %} + {% comment %} <div class="alert alert-danger" role="alert"> {% endcomment %} + {% comment %} {{ formset_add.non_form_errors }} {% endcomment %} + {% comment %} </div> {% endcomment %} + {% comment %} {% endif %} {% endcomment %} + {% comment %} <table> {% endcomment %} + {% comment %} {% for form in formset_add %} {% endcomment %} + {% comment %} {{form}} {% endcomment %} + {% comment %} {% endfor %} {% endcomment %} + {% comment %} </table> {% endcomment %} {% endblock %} </div> </div> 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]) }) |