diff options
Diffstat (limited to 'archaeological_operations/views.py')
-rw-r--r-- | archaeological_operations/views.py | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index f5d1c514f..647f4b485 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -410,7 +410,6 @@ def operation_delete(request, pk): def operation_modify_parcels(request, pk): - # TODO: add quick add form formset_class = SelectedParcelGeneralFormSet operation = models.Operation.objects.get(pk=pk) parcels = models.Parcel.objects.filter(operation=pk).all() @@ -439,22 +438,18 @@ def operation_modify_parcels(request, pk): 'form-MAX_NUM_FORMS': 100, } - if request.method == 'POST': #TODO + if request.method == 'POST': new_data = dict(request.POST) new_data = {k: new_data[k][0] for k in new_data} # convert POST to classic dict new_data.update(data) formset = formset_class(new_data) - for form in formset: #DEBUG - print(form.errors) #DEBUG - + print(new_data) if formset.is_valid(): - print(formset.cleaned_data) #DEBUG - post_data = formset.cleaned_data - - for data in post_data: + for data in formset.cleaned_data: if (not data.get('parcel_number') or not data.get('section')) and \ not data.get('public_domain'): continue + current_parcel = None if data.get("pk"): try: @@ -479,26 +474,26 @@ def operation_modify_parcels(request, pk): current_parcel.section = data.get("section") current_parcel.parcel_number = data.get("parcel_number") current_parcel.town = models.Town.objects.get(pk=int(data.get("town"))) + current_parcel.public_domain = data.get("public_domain") current_parcel.save() else: parcel_to_add = models.Parcel.objects.create( year = data.get("year"), section = data.get("section"), parcel_number = data.get("parcel_number"), - town = models.Town.objects.get(pk=int(data.get("town"))) + town = models.Town.objects.get(pk=int(data.get("town"))), + public_domain = data.get("public_domain") ) operation.parcels.add(parcel_to_add) return redirect(reverse("operation-parcels-modify", args=[pk])) else: print(formset.errors) print(formset.non_form_errors()) - print("je passe ici") else: formset = formset_class(initial=initial, data=data) - - for form in formset:# DEBUG - print(form.as_table())# DEBUG - +# + # for form in formset: + # print(form.as_table()) return render(request, 'ishtar/forms/operation_modify_parcels.html', { 'formset': formset, "url": reverse("operation-parcels-modify", args=[pk]) |