From 34c29d70766970633bd19db8e60657900401e8a2 Mon Sep 17 00:00:00 2001 From: Thibault Jouannic Date: Tue, 5 Nov 2024 09:23:21 +0100 Subject: [PATCH 1/6] Remove the obsolete `lineaire_detruit` field --- .../regulations/conditionnalitepac.py | 22 +++++-------------- .../tests/test_conditionnalite_pac.py | 13 ++++++----- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/envergo/moulinette/regulations/conditionnalitepac.py b/envergo/moulinette/regulations/conditionnalitepac.py index 3386c8123..019aa83fd 100644 --- a/envergo/moulinette/regulations/conditionnalitepac.py +++ b/envergo/moulinette/regulations/conditionnalitepac.py @@ -6,14 +6,6 @@ class Bcae8Form(forms.Form): - lineaire_detruit = DisplayIntegerField( - label="Linéaire de haie détruit :", - required=True, - min_value=0, - widget=forms.TextInput(attrs={"placeholder": "En mètres"}), - display_unit="m", - ) - lineaire_total = DisplayIntegerField( label="Linéaire total de haie sur l’exploitation :", required=True, @@ -101,20 +93,18 @@ class Bcae8(CriterionEvaluator): } def get_result_data(self): - is_petit = False - if "lineaire_detruit" in self.catalog and "lineaire_total" in self.catalog: - is_petit = ( - self.catalog["lineaire_detruit"] <= 5 - or self.catalog["lineaire_detruit"] - <= 0.02 * self.catalog["lineaire_total"] - ) + lineaire_detruit = self.catalog["haies"].length_to_remove() + is_petit = ( + lineaire_detruit <= 5 + or lineaire_detruit <= 0.02 * self.catalog["lineaire_total"] + ) return ( self.catalog["profil"], self.catalog["motif"], self.catalog["reimplantation"], is_petit, - self.catalog.get("lineaire_detruit"), + lineaire_detruit, self.catalog.get("amenagement_dup"), self.catalog.get("motif_qc"), ) diff --git a/envergo/moulinette/tests/test_conditionnalite_pac.py b/envergo/moulinette/tests/test_conditionnalite_pac.py index 4acb6743b..e7b5156ae 100644 --- a/envergo/moulinette/tests/test_conditionnalite_pac.py +++ b/envergo/moulinette/tests/test_conditionnalite_pac.py @@ -1,3 +1,5 @@ +from unittest.mock import MagicMock + import pytest from envergo.geodata.conftest import france_map # noqa @@ -58,20 +60,21 @@ def test_conditionnalite_pac_for_agri_pac(): "motif": "chemin_acces", "reimplantation": "remplacement", "department": "44", + "haies": MagicMock(), } moulinette = MoulinetteHaie(data, data, False) assert moulinette.is_evaluation_available() assert moulinette.result == "non_disponible", data - data["lineaire_detruit"] = 5 + data["haies"].length_to_remove.return_value = 5 data["lineaire_total"] = 100 moulinette = MoulinetteHaie(data, data, False) assert moulinette.is_evaluation_available() assert moulinette.result == "non_soumis", data assert moulinette.conditionnalite_pac.bcae8.result_code == "non_soumis_petit", data - data["lineaire_detruit"] = 6 + data["haies"].length_to_remove.return_value = 6 data["lineaire_total"] = 100 moulinette = MoulinetteHaie(data, data, False) assert moulinette.is_evaluation_available() @@ -80,7 +83,7 @@ def test_conditionnalite_pac_for_agri_pac(): moulinette.conditionnalite_pac.bcae8.result_code == "soumis_remplacement" ), data - data["lineaire_detruit"] = 6 + data["haies"].length_to_remove.return_value = 6 data["lineaire_total"] = 300 moulinette = MoulinetteHaie(data, data, False) assert moulinette.is_evaluation_available() @@ -101,7 +104,7 @@ def test_conditionnalite_pac_for_agri_pac(): moulinette.conditionnalite_pac.bcae8.result_code == "soumis_chemin_acces" ), data - data["lineaire_detruit"] = 11 + data["haies"].length_to_remove.return_value = 11 moulinette = MoulinetteHaie(data, data, False) assert moulinette.is_evaluation_available() assert moulinette.result == "interdit", data @@ -184,7 +187,7 @@ def test_conditionnalite_pac_for_agri_pac(): moulinette.conditionnalite_pac.bcae8.result_code == "interdit_chemin_acces" ), data - data["lineaire_detruit"] = 10 + data["haies"].length_to_remove.return_value = 10 moulinette = MoulinetteHaie(data, data, False) assert moulinette.is_evaluation_available() assert moulinette.result == "soumis", data From 3009864a8883c34862c53c95146fdb24b82c844c Mon Sep 17 00:00:00 2001 From: Thibault Jouannic Date: Tue, 5 Nov 2024 09:30:50 +0100 Subject: [PATCH 2/6] Fix broken test --- envergo/moulinette/tests/test_conditionnalite_pac.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/envergo/moulinette/tests/test_conditionnalite_pac.py b/envergo/moulinette/tests/test_conditionnalite_pac.py index e7b5156ae..f582002ae 100644 --- a/envergo/moulinette/tests/test_conditionnalite_pac.py +++ b/envergo/moulinette/tests/test_conditionnalite_pac.py @@ -29,11 +29,15 @@ def conditionnalite_pac_criteria(france_map): # noqa def test_conditionnalite_pac_only_for_agri_pac(): ConfigHaieFactory() + haies = MagicMock() + haies.length_to_remove.return_value = 10 data = { "profil": "autre", "motif": "chemin_acces", "reimplantation": "remplacement", "department": "44", + "haies": haies, + "lineaire_total": 100, } for motif_choice in [ "transfert_parcelles", From b4875b6f287437786f2a76527dbabd7456dbd664 Mon Sep 17 00:00:00 2001 From: Thibault Jouannic Date: Tue, 5 Nov 2024 11:29:10 +0100 Subject: [PATCH 3/6] Add error message if no hedge to remove is set --- envergo/moulinette/forms/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/envergo/moulinette/forms/__init__.py b/envergo/moulinette/forms/__init__.py index 4a986e463..dcc49ac5f 100644 --- a/envergo/moulinette/forms/__init__.py +++ b/envergo/moulinette/forms/__init__.py @@ -247,6 +247,15 @@ def clean(self): return data + def clean_haies(self): + haies = self.cleaned_data["haies"] + if haies.length_to_remove() == 0: + self.add_error( + "haies", + "Vous devez indiquer les haies à arracher.", + ) + return haies + class TriageFormHaie(forms.Form): department = DisplayCharField( From 8601204a47f474605b880fb7eaa515eb3a0258a8 Mon Sep 17 00:00:00 2001 From: Thibault Jouannic Date: Wed, 6 Nov 2024 09:53:01 +0100 Subject: [PATCH 4/6] Add missing check on variable existence --- envergo/moulinette/regulations/conditionnalitepac.py | 10 ++++++---- envergo/moulinette/tests/test_conditionnalite_pac.py | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/envergo/moulinette/regulations/conditionnalitepac.py b/envergo/moulinette/regulations/conditionnalitepac.py index 019aa83fd..81bf0f5ef 100644 --- a/envergo/moulinette/regulations/conditionnalitepac.py +++ b/envergo/moulinette/regulations/conditionnalitepac.py @@ -93,11 +93,13 @@ class Bcae8(CriterionEvaluator): } def get_result_data(self): + is_petit = False lineaire_detruit = self.catalog["haies"].length_to_remove() - is_petit = ( - lineaire_detruit <= 5 - or lineaire_detruit <= 0.02 * self.catalog["lineaire_total"] - ) + if "lineaire_total" in self.catalog: + is_petit = ( + lineaire_detruit <= 5 + or lineaire_detruit <= 0.02 * self.catalog["lineaire_total"] + ) return ( self.catalog["profil"], diff --git a/envergo/moulinette/tests/test_conditionnalite_pac.py b/envergo/moulinette/tests/test_conditionnalite_pac.py index f582002ae..82a6479ba 100644 --- a/envergo/moulinette/tests/test_conditionnalite_pac.py +++ b/envergo/moulinette/tests/test_conditionnalite_pac.py @@ -37,7 +37,6 @@ def test_conditionnalite_pac_only_for_agri_pac(): "reimplantation": "remplacement", "department": "44", "haies": haies, - "lineaire_total": 100, } for motif_choice in [ "transfert_parcelles", From 3d1ee2a7d4498602280c24ddde1f9028b1f04678 Mon Sep 17 00:00:00 2001 From: Thibault Jouannic Date: Wed, 6 Nov 2024 10:48:56 +0100 Subject: [PATCH 5/6] Fix a typo in a label --- envergo/moulinette/regulations/conditionnalitepac.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envergo/moulinette/regulations/conditionnalitepac.py b/envergo/moulinette/regulations/conditionnalitepac.py index 81bf0f5ef..e0a09d80e 100644 --- a/envergo/moulinette/regulations/conditionnalitepac.py +++ b/envergo/moulinette/regulations/conditionnalitepac.py @@ -7,7 +7,7 @@ class Bcae8Form(forms.Form): lineaire_total = DisplayIntegerField( - label="Linéaire total de haie sur l’exploitation :", + label="Linéaire total de haies sur l’exploitation :", required=True, min_value=0, widget=forms.TextInput(attrs={"placeholder": "En mètres"}), From 609f695841d5b67778b2f55a47a3c3439223de46 Mon Sep 17 00:00:00 2001 From: Thibault Jouannic Date: Wed, 6 Nov 2024 11:39:34 +0100 Subject: [PATCH 6/6] Make the ui input modal full screen --- envergo/static/sass/project_haie.scss | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/envergo/static/sass/project_haie.scss b/envergo/static/sass/project_haie.scss index dc2fa372d..48e8d1cbb 100644 --- a/envergo/static/sass/project_haie.scss +++ b/envergo/static/sass/project_haie.scss @@ -264,11 +264,14 @@ div#app { dialog#hedge-input-modal { width: 100%; + max-width: 100%; height: 100%; + max-height: 100%; overscroll-behavior: contain; overflow: hidden; border: none; - filter: drop-shadow(var(--lifted-shadow)); + margin: 0; + padding: 0; } div#statistics {