summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCefin <kevon@tuta.io>2022-01-21 16:20:53 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:20:59 +0100
commitf613896e19caaa1f2884f480d1408f8c8ec01843 (patch)
tree5eb1b7b6d0ccebd7e61cdf309d9f90de91174543
parentb70efa7223b3828519cce73b8104a739cf9a7dc3 (diff)
downloadIshtar-f613896e19caaa1f2884f480d1408f8c8ec01843.tar.bz2
Ishtar-f613896e19caaa1f2884f480d1408f8c8ec01843.zip
Operation - Parcels - Modify: get step/tests/beginning of post step
-rw-r--r--archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html22
-rw-r--r--archaeological_operations/tests.py44
-rw-r--r--archaeological_operations/views.py60
3 files changed, 77 insertions, 49 deletions
diff --git a/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html b/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html
index 9aebe20fa..9fb75b3d4 100644
--- a/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html
+++ b/archaeological_operations/templates/ishtar/forms/operation_modify_parcels.html
@@ -9,34 +9,20 @@
</button>
</div>
<form enctype="multipart/form-data" action="{{url}}" method="post" id="{{ formset.form_slug }}">
+ {{ formset.management_form }}
{% csrf_token %}
<div class="modal-body body-scroll">
<div class='form'>
{% block main_form %}
- {{ formset.management_form }}
{% if formset.non_form_errors %}
<div class="alert alert-danger" role="alert">
{{ formset.non_form_errors }}
</div>
{% endif %}
<table>
- <tr>
- {% for form in formset %}
- {{form}}
- {% if form.name != 'pk' %}
- {% if form.required %}
- <th
- {% else %}
- <td
- {% endif %}
- {% if not forloop.last %}
- rowspan='2'
- {% endif %}>
- {{ form.label}}
- {% endif %}
- </td>
- {% endfor %}
- </tr>
+ {% for form in formset %}
+ {{form}}
+ {% endfor %}
<tr>
<td>
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 371857337..5d41d0202 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -1642,6 +1642,50 @@ class ParcelTest(ImportTest, TestCase):
'recognized in "%s"' % (str(not_imported), value),
)
+ def test_operation_parcel_modify(self):
+ username, password, user = create_user(
+ username="Gandalf", password="ushallpass"
+ )
+ user.user_permissions.add(
+ Permission.objects.get(codename="view_own_operation")
+ )
+ user.user_permissions.add(
+ Permission.objects.get(codename="change_own_operation")
+ )
+
+ c = Client()
+ c.login(username=username, password=password)
+
+ town_1 = Town.objects.create(name="Minas Morgul", numero_insee="10920")
+ town_2 = Town.objects.create(name="Minas Tirith", numero_insee="10901")
+ parcel_1 = models.Parcel.objects.create(town=town_1, year=2640, section="M", parcel_number="1", public_domain=False)
+ parcel_2 = models.Parcel.objects.create(town=town_2, year=2620, section="M", parcel_number="2", public_domain=True)
+
+ operation = create_operation(user)
+ operation.towns.add(town_1)
+ operation.towns.add(town_2)
+ operation.parcels.add(parcel_1)
+ operation.parcels.add(parcel_2)
+
+ response = c.get(reverse("operation-parcels-modify", kwargs={"pk": operation.pk}))
+
+ self.assertEqual(response.status_code, 200)
+ print(response)
+ self.assertInHTML(
+ '<select id="id_form-0-town" class="form-control" name="form-0-town"><select>',
+ town_1.name,
+ count=1
+ )
+ self.assertContains(response, town_1.name)
+ print(response)
+ self.assertContains(response, town_2.name)
+ self.assertContains(response, parcel_1.year)
+ self.assertContains(response, parcel_2.year)
+ self.assertContains(response, parcel_1.section)
+ self.assertContains(response, parcel_2.section)
+ self.assertContains(response, parcel_1.parcel_number)
+ self.assertContains(response, parcel_2.parcel_number)
+
def create_orga(user):
orga_type, created = OrganizationType.objects.get_or_create(txt_idx="operator")
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 0b71331f8..d6ebd940c 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -31,12 +31,7 @@ from django.forms import formset_factory
from archaeological_operations import models
from archaeological_operations import forms
-from archaeological_operations.forms import (
- SelectedParcelForm,
- ParcelFormSet,
- SelectedParcelFormSet,
- SelectedParcelGeneralFormSet,
-)
+from archaeological_operations.forms import SelectedParcelGeneralFormSet
from archaeological_operations import wizards
from ishtar_common.forms import ClosingDateFormSelection, FinalForm, FinalDeleteForm
from ishtar_common.models import (
@@ -419,39 +414,42 @@ def operation_modify_parcels(request, pk):
operation = models.Operation.objects.get(pk=pk)
parcels = models.Parcel.objects.filter(operation=pk).all()
data = {}
+ available_towns = []
+
+ for town in operation.towns.all():
+ available_towns.append((town.id, town.name))
if request.method == 'POST': #TODO
- formset = formset_class(request.POST, request.FILES)
+ print(request.POST)
+ formset = formset_class(request.POST or None, request.FILES or None)
if formset.is_valid():
- pass
+ print(formset.cleaned_data)
else:
formset = formset_class()
else:
- towns_array = []
- parcels_array = []
- info = {}
- for parcel in parcels:
- print(parcel.pk)
- print(parcel.town)
- #towns_array.append(parcel.town)
- parcels_array.append(int(parcel.pk))
- # data['TOWNS'] = towns_array
- # data['PARCELS'] = parcels_array
- data['form-TOTAL_FORMS'] = 3
- # TODO: feed initial with current parcels
- print("parcel_array : ")
- for p in parcels_array:
- print(p)
initial = []
- initial = {'PARCELS': parcels_array}
- print(initial)
- # if parcels:
- # for parcel in parcels:
- data['form-INITIAL_FORMS'] = len(initial)
+ for parcel in parcels:
+ town = models.Town.objects.get(pk=parcel.town_id)
+ initial.append({
+ "pk": parcel.pk,
+ "town": town.pk,
+ "year": parcel.year,
+ "section": parcel.section,
+ "parcel_number": parcel.parcel_number,
+ "public_domain": parcel.public_domain
+ })
+
+ data = {
+ 'TOWNS': available_towns,
+ 'form-TOTAL_FORMS': len(initial),
+ 'form-INITIAL_FORMS': 0,
+ }
+
formset = formset_class(initial=initial, data=data)
- for form in formset:
- print(form.as_table())
- #formset = SelectedParcelGeneralFormSet()
+
+ for form in formset:# DEBUG
+ print(form.as_table())# DEBUG
+
return render(request, 'ishtar/forms/operation_modify_parcels.html', {
'formset': formset,
})