Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mauvaise url lorsque la page formulaire du simulateur renvoie une erreur (GUH) #444

Merged
merged 34 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ceb0956
ui
pyDez Sep 27, 2024
20f510c
Merge remote-tracking branch 'origin/main' into feature/guh-v1.3
pyDez Sep 27, 2024
46cb585
POST departement
pyDez Sep 30, 2024
d468ca8
form result
pyDez Sep 30, 2024
0f02469
Merge remote-tracking branch 'origin/main' into feature/guh-v1.3
pyDez Sep 30, 2024
8375af2
add config model + fixture
pyDez Sep 30, 2024
af94acb
UI for not activated department
pyDez Oct 1, 2024
7a32d7e
UI for activated departments
pyDez Oct 1, 2024
6ac9fdd
nav bar
pyDez Oct 1, 2024
e0ece05
selectable departments
pyDez Oct 1, 2024
0d687d0
Merge remote-tracking branch 'origin/main' into feature/guh-v1.3
pyDez Oct 1, 2024
5400ea6
urls
pyDez Oct 1, 2024
ea3fa70
do not raise if no activated dpt
pyDez Oct 1, 2024
aac6e8c
handle unexpected department
pyDez Oct 1, 2024
d5fe07d
improve display
pyDez Oct 1, 2024
d02ef9c
fix tests
pyDez Oct 1, 2024
1e411fa
missing one
pyDez Oct 1, 2024
52a3645
a bit of cleaning
pyDez Oct 1, 2024
bd87eaf
add admin ui
pyDez Oct 3, 2024
e6bcf63
inverse home bloc
pyDez Oct 3, 2024
e8a4571
remove available soon dept + redirect to home when triage with no dept
pyDez Oct 3, 2024
e262929
use result view for rejected triage
pyDez Oct 4, 2024
ccc154b
fix test urls
pyDez Oct 4, 2024
04fb3a1
Merge branch 'feature/guh-v1.3' into feature/moulinette-urls
pyDez Oct 4, 2024
ba90454
post to moulinette home
pyDez Oct 4, 2024
da3611a
Merge remote-tracking branch 'origin/main' into feature/guh-v1.3
pyDez Oct 7, 2024
69ab6fe
design review
pyDez Oct 7, 2024
d7fa6e2
review part 1
pyDez Oct 7, 2024
601fa2e
Merge branch 'feature/guh-v1.3' into feature/moulinette-urls
pyDez Oct 7, 2024
5672775
Merge remote-tracking branch 'origin/main' into feature/moulinette-urls
pyDez Oct 7, 2024
33df819
rename moulinette_config into config_amenagement
pyDez Oct 7, 2024
35f58a6
typo
pyDez Oct 7, 2024
73a1f4e
trigger scalingo
pyDez Oct 7, 2024
4a203ad
fixture
pyDez Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def site() -> Site:

HAIE_URLS = [
"triage",
"triage_result",
]

AMENAGEMENT_URLS = [
Expand Down
3 changes: 2 additions & 1 deletion config/urls_haie.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.urls import include, path
from django.utils.translation import gettext_lazy as _

from .urls import urlpatterns as common_urlpatterns

urlpatterns = [
path("", include("envergo.pages.urls_haie")),
path("indre/", include("envergo.moulinette.urls_haie")),
path(_("moulinette/"), include("envergo.moulinette.urls_haie")),
] + common_urlpatterns
8 changes: 4 additions & 4 deletions envergo/evaluations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from phonenumber_field.formfields import PhoneNumberField

from envergo.evaluations.models import USER_TYPES, Request
from envergo.evaluations.utils import extract_department
from envergo.evaluations.utils import extract_department_from_address
from envergo.evaluations.validators import application_number_validator
from envergo.geodata.models import Department
from envergo.utils.fields import NoIdnEmailField
Expand Down Expand Up @@ -119,7 +119,7 @@ def clean(self):
department_input = data.get("department", None)
if not department_input:
# extract department from address
department_input = extract_department(address)
department_input = extract_department_from_address(address)

if department_input and department_input not in address:
# when a town is selected on its own, without a complete address, there is no zip code.
Expand All @@ -128,10 +128,10 @@ def clean(self):

department = (
Department.objects.filter(department=department_input)
.select_related("moulinette_config")
.select_related("configamenagement")
.first()
)
if department and not department.is_activated():
if department and not department.is_amenagement_activated():
self.add_error(
"department",
ValidationError(
Expand Down
2 changes: 1 addition & 1 deletion envergo/evaluations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def get_moulinette_config(self):
lng, lat = params["lng"], params["lat"]
coords = Point(float(lng), float(lat), srid=EPSG_WGS84)
department = Department.objects.filter(geometry__contains=coords).first()
return department.moulinette_config if department else None
return department.configamenagement if department else None

def get_moulinette(self):
"""Return the moulinette instance for this evaluation."""
Expand Down
13 changes: 8 additions & 5 deletions envergo/evaluations/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
generate_reference,
)
from envergo.evaluations.tests.factories import EvaluationFactory, RequestFactory
from envergo.moulinette.tests.factories import CriterionFactory, MoulinetteConfigFactory
from envergo.moulinette.tests.factories import (
ConfigAmenagementFactory,
CriterionFactory,
)

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -92,7 +95,7 @@ def test_create_eval_fails_when_it_already_exists(client, admin_user, eval_reque
def test_evaluation_email_sending(admin_client, evaluation, mailoutbox):
# Make sure the "loi sur l'eau" result will be set
CriterionFactory()
MoulinetteConfigFactory()
ConfigAmenagementFactory()

url = reverse("admin:evaluations_evaluation_email_avis", args=[evaluation.pk])
res = admin_client.get(url)
Expand Down Expand Up @@ -126,7 +129,7 @@ def test_evaluation_email_sending(admin_client, evaluation, mailoutbox):
def test_evaluation_email_throttling(admin_client, evaluation, mailoutbox):
# Make sure the "loi sur l'eau" result will be set
CriterionFactory()
MoulinetteConfigFactory()
ConfigAmenagementFactory()

url = reverse("admin:evaluations_evaluation_email_avis", args=[evaluation.pk])
res = admin_client.get(url)
Expand Down Expand Up @@ -156,7 +159,7 @@ def test_evaluation_email_throttling(admin_client, evaluation, mailoutbox):
def test_evaluation_email_recipient_overriding(admin_client, evaluation, mailoutbox):
# Make sure the "loi sur l'eau" result will be set
CriterionFactory()
MoulinetteConfigFactory()
ConfigAmenagementFactory()

url = reverse("admin:evaluations_evaluation_email_avis", args=[evaluation.pk])
res = admin_client.get(url)
Expand All @@ -180,7 +183,7 @@ def test_evaluation_email_recipient_overriding(admin_client, evaluation, mailout
def test_evaluation_email_with_empty_recipients(admin_client, evaluation, mailoutbox):
# Make sure the "loi sur l'eau" result will be set
CriterionFactory()
MoulinetteConfigFactory()
ConfigAmenagementFactory()

url = reverse("admin:evaluations_evaluation_email_avis", args=[evaluation.pk])
res = admin_client.get(url)
Expand Down
4 changes: 2 additions & 2 deletions envergo/evaluations/tests/test_eval_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from envergo.geodata.conftest import bizous_town_center, france_map, france_zh # noqa
from envergo.moulinette.regulations import RequiredAction, Stake
from envergo.moulinette.tests.factories import (
ConfigAmenagementFactory,
CriterionFactory,
MoulinetteConfigFactory,
PerimeterFactory,
RegulationFactory,
)
Expand All @@ -25,7 +25,7 @@ def override_settings(settings):

@pytest.fixture(autouse=True)
def moulinette_config(france_map, france_zh, loire_atlantique_department): # noqa
MoulinetteConfigFactory(
ConfigAmenagementFactory(
department=loire_atlantique_department,
is_activated=True,
ddtm_water_police_email="[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions envergo/evaluations/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from envergo.evaluations.forms import WizardAddressForm
from envergo.geodata.conftest import loire_atlantique_department # noqa
from envergo.moulinette.tests.factories import MoulinetteConfigFactory
from envergo.moulinette.tests.factories import ConfigAmenagementFactory

pytestmark = pytest.mark.django_db

Expand All @@ -17,7 +17,7 @@ def form_data():

@pytest.fixture(autouse=True)
def moulinette_config(loire_atlantique_department): # noqa
MoulinetteConfigFactory(
ConfigAmenagementFactory(
department=loire_atlantique_department,
is_activated=True,
ddtm_water_police_email="[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions envergo/evaluations/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from envergo.geodata.conftest import loire_atlantique_department # noqa
from envergo.geodata.conftest import bizous_town_center, france_map # noqa
from envergo.moulinette.tests.factories import (
ConfigAmenagementFactory,
CriterionFactory,
MoulinetteConfigFactory,
PerimeterFactory,
RegulationFactory,
)
Expand All @@ -19,7 +19,7 @@

@pytest.fixture(autouse=True)
def moulinette_config(france_map, loire_atlantique_department): # noqa
MoulinetteConfigFactory(
ConfigAmenagementFactory(
department=loire_atlantique_department,
is_activated=True,
ddtm_water_police_email="[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions envergo/evaluations/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
VersionFactory,
)
from envergo.geodata.conftest import loire_atlantique_department # noqa
from envergo.moulinette.tests.factories import MoulinetteConfigFactory
from envergo.moulinette.tests.factories import ConfigAmenagementFactory

pytestmark = pytest.mark.django_db

Expand All @@ -26,7 +26,7 @@ def autouse_site(site):

@pytest.fixture()
def moulinette_config(loire_atlantique_department): # noqa
MoulinetteConfigFactory(
ConfigAmenagementFactory(
department=loire_atlantique_department,
is_activated=True,
ddtm_water_police_email="[email protected]",
Expand All @@ -37,7 +37,7 @@ def moulinette_config(loire_atlantique_department): # noqa

@pytest.fixture()
def unactivated_moulinette_config(loire_atlantique_department): # noqa
MoulinetteConfigFactory(
ConfigAmenagementFactory(
department=loire_atlantique_department,
is_activated=False,
ddtm_water_police_email="[email protected]",
Expand Down
7 changes: 5 additions & 2 deletions envergo/evaluations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ def extract_postal_code(address):
return None


def extract_department(address):
def extract_department_from_address(address):
"""Extract the department as two (or three) digits from a stringified address.
return None if no department is found.
"""
postal_code = extract_postal_code(address)
return extract_department_from_postal_code(postal_code)


def extract_department_from_postal_code(postal_code):
department = None
if postal_code:
department = postal_code[:2]
Expand All @@ -33,5 +37,4 @@ def extract_department(address):
department = "2A" # Corse-du-Sud
elif 20200 <= code_number <= 20620:
department = "2B" # Haute-Corse

return department
4 changes: 2 additions & 2 deletions envergo/geodata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class Meta:
def __str__(self):
return self.get_department_display()

def is_activated(self):
config = getattr(self, "moulinette_config", None)
def is_amenagement_activated(self):
config = getattr(self, "configamenagement", None)
return config and config.is_activated


Expand Down
27 changes: 21 additions & 6 deletions envergo/moulinette/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from envergo.geodata.admin import DepartmentsListFilter
from envergo.moulinette.models import (
REGULATIONS,
ConfigAmenagement,
ConfigHaie,
Criterion,
MoulinetteConfig,
MoulinetteTemplate,
Perimeter,
Regulation,
Expand Down Expand Up @@ -250,7 +251,7 @@ def departments(self, obj):
return obj.activation_map.departments


class MoulinetteConfigForm(forms.ModelForm):
class ConfigAmenagementForm(forms.ModelForm):
regulations_available = forms.MultipleChoiceField(
label=_("Regulations available"), required=False, choices=REGULATIONS
)
Expand All @@ -276,7 +277,7 @@ def clean_criteria_values(self):


class MoulinetteConfigTemplateForm(forms.ModelForm):
"""Form to edit a MoulinetteTemplate in a MoulinetteConfig.
"""Form to edit a MoulinetteTemplate in a ConfigAmenagement.

We remove every key that is not a real template (autorisation_urba_*, etc.)
"""
Expand All @@ -295,10 +296,10 @@ class MoulinetteConfigTemplateInline(MoulinetteTemplateInline):
form = MoulinetteConfigTemplateForm


@admin.register(MoulinetteConfig)
class MoulinetteConfigAdmin(admin.ModelAdmin):
@admin.register(ConfigAmenagement)
class ConfigAmenagementAdmin(admin.ModelAdmin):
list_display = ["department", "is_activated", "zh_doubt"]
form = MoulinetteConfigForm
form = ConfigAmenagementForm
inlines = [MoulinetteConfigTemplateInline]
list_filter = ["is_activated", "zh_doubt"]

Expand All @@ -315,3 +316,17 @@ def get_queryset(self, request):
class MoulinetteTemplateAdmin(admin.ModelAdmin):
list_display = ["config", "key"]
search_fields = ["content"]


@admin.register(ConfigHaie)
class ConfigHaieAdmin(admin.ModelAdmin):
list_display = ["department", "is_activated", "department_guichet_unique_url"]
list_filter = ["is_activated"]

def get_queryset(self, request):
qs = super().get_queryset(request)
return (
qs.select_related("department")
.order_by("department__department")
.defer("department__geometry")
)
1 change: 0 additions & 1 deletion envergo/moulinette/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class TriageFormHaie(forms.Form):
department = DisplayCharField(
label="Département",
required=True,
initial="36",
get_display_value=lambda x: dict(DEPARTMENT_CHOICES).get(x, "Inconnu"),
)
element = DisplayChoiceField(
Expand Down
Loading
Loading