Skip to content

Commit

Permalink
Merge pull request #229 from MTES-MCT/new_wording
Browse files Browse the repository at this point in the history
Refonte des formulations
  • Loading branch information
thibault authored Sep 4, 2023
2 parents 3a08f78 + bb08fa5 commit 8741d12
Show file tree
Hide file tree
Showing 94 changed files with 575 additions and 543 deletions.
8 changes: 4 additions & 4 deletions .djlintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"indent": 2,
"blank_line_after_tag": "load,extends,include",
"line_break_after_multiline_tag": "true",
"max_line_length": "120",
"preserve_blank_lines": "false",
"blank_line_after_tag": "load,extends",
"line_break_after_multiline_tag": false,
"max_line_length": 120,
"preserve_blank_lines": true,
"ignore": "T002,T003,H021,D018,H022,H006,H029"
}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
additional_dependencies: [flake8-isort]

- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.28.0
rev: v1.32.1
hooks:
- id: djlint-reformat-django
- id: djlint-django
Expand Down
4 changes: 3 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
path(
_("password_reset/"),
auth_views.PasswordResetView.as_view(
subject_template_name="emails/password_reset_subject.txt",
email_template_name="emails/password_reset.txt",
html_email_template_name="emails/password_reset.html",
),
Expand Down Expand Up @@ -51,8 +52,9 @@
path("", include("envergo.pages.urls")),
path(_("accounts/"), include(auth_patterns)),
path(_("users/"), include("envergo.users.urls")),
path("evaluations/", include("envergo.evaluations.redirect_urls")),
path("évaluations/", include("envergo.evaluations.redirect_urls")),
path("evaluations/", include("envergo.evaluations.urls")),
path("avis/", include("envergo.evaluations.urls")),
path(_("moulinette/"), include("envergo.moulinette.urls")),
path(_("geo/"), include("envergo.geodata.urls")),
path(_("analytics/"), include("envergo.analytics.urls")),
Expand Down
4 changes: 2 additions & 2 deletions envergo/analytics/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FeedbackRespondForm(forms.Form):

feedback = forms.ChoiceField(
required=True,
label="Cette évaluation vous est-elle utile ?",
label="Cette simulation vous est-elle utile ?",
choices=FEEDBACK_CHOICES,
)
moulinette_data = forms.JSONField(required=False, widget=forms.HiddenInput)
Expand All @@ -45,7 +45,7 @@ class FeedbackRespondForm(forms.Form):
class FeedbackForm(forms.Form):
feedback = forms.ChoiceField(
required=True,
label="Cette évaluation vous est-elle utile ?",
label="Cette simulation vous est-elle utile ?",
choices=FEEDBACK_CHOICES,
widget=forms.HiddenInput,
)
Expand Down
6 changes: 3 additions & 3 deletions envergo/evaluations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def rappel_reglementaire(self, request, object_id):
else:
context = {
**self.admin_site.each_context(request),
"title": "Rappel réglementaire",
"title": "Avis réglementaire",
"subtitle": str(evaluation),
"object_id": object_id,
"evaluation": evaluation,
Expand Down Expand Up @@ -389,7 +389,7 @@ def parcels_geojson(self, obj):
link = f"<a href='{parcel_export_url}'>Télécharger en geojson</a>"
return mark_safe(link)

@admin.display(description=_("Evaluation"), ordering="evaluation")
@admin.display(description="Avis", ordering="evaluation")
def evaluation_link(self, obj):
if not obj.evaluation:
return ""
Expand Down Expand Up @@ -444,7 +444,7 @@ def response_change(self, request, obj):
else:
return super().response_change(request, obj)

@admin.action(description=_("Create an evaluation from this request"))
@admin.action(description=_("Create a regulatory notice from this request"))
def make_evaluation(self, request, queryset):
"""Create an evaluation matching an existing eval request."""

Expand Down
2 changes: 1 addition & 1 deletion envergo/evaluations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EvaluationSearchForm(forms.Form):

reference = forms.CharField(
label=_("EnvErgo reference"),
help_text=_("The value you received when you requested an evaluation."),
help_text=_("The value you received when you requested a regulatory notice."),
max_length=64,
)

Expand Down
25 changes: 14 additions & 11 deletions envergo/evaluations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def params_from_url(url):


class Evaluation(models.Model):
"""A single evaluation for a building permit application."""
"""A single evaluation for a building permit application.
Note: the domaine technical name evolved from "évaluation" to "avis réglementaire",
often shortened in "avis".
"""

uid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
reference = models.CharField(
Expand All @@ -107,8 +112,8 @@ class Evaluation(models.Model):

request = models.OneToOneField(
"evaluations.Request",
verbose_name=_("Request"),
help_text=_("Does this evaluation answers to an existing request?"),
verbose_name="Demande associée",
help_text=_("Does this regulatory notice answers to an existing request?"),
on_delete=models.SET_NULL,
null=True,
blank=True,
Expand Down Expand Up @@ -156,8 +161,8 @@ class Evaluation(models.Model):
created_at = models.DateTimeField(_("Date created"), default=timezone.now)

class Meta:
verbose_name = _("Evaluation")
verbose_name_plural = _("Evaluations")
verbose_name = "Avis"
verbose_name_plural = "Avis"

def __str__(self):
return self.reference
Expand Down Expand Up @@ -224,7 +229,7 @@ def can_send_regulatory_reminder(self):
return self.request and self.moulinette_url

def get_regulatory_reminder_email(self, request):
"""Generates a "rappel réglementaire" email for this evaluation.
"""Generates a "avis réglementaire" email for this evaluation.
The content of the email will vary depending on the evaluation result
and the field values in the eval requset.
Expand All @@ -233,9 +238,7 @@ def get_regulatory_reminder_email(self, request):
try:
evalreq = self.request
except Request.DoesNotExist:
raise ValueError(
"Impossible de générer un rappel reglementaire sans demande"
)
raise ValueError("Impossible de générer un avis reglementaire sans demande")
config = self.get_moulinette_config()
moulinette = self.get_moulinette()
result = moulinette.loi_sur_leau.result
Expand Down Expand Up @@ -290,9 +293,9 @@ def get_regulatory_reminder_email(self, request):
bcc_recipients.append(settings.DEFAULT_FROM_EMAIL)

if result == "non_soumis":
subject = "Évaluation EnvErgo"
subject = "Avis réglementaire EnvErgo"
else:
subject = "Rappel réglementaire Loi sur l'eau"
subject = "Avis réglementaire Loi sur l'eau"

if self.address:
subject += f" / {self.address}"
Expand Down
6 changes: 2 additions & 4 deletions envergo/evaluations/redirect_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from django.views.generic import RedirectView

urlpatterns = [
path("", RedirectView.as_view(url="/evaluations", permanent=True)),
path(
"<path:url>", RedirectView.as_view(url="/evaluations/%(url)s", permanent=True)
),
path("", RedirectView.as_view(url="/avis", permanent=True)),
path("<path:url>", RedirectView.as_view(url="/avis/%(url)s", permanent=True)),
]
4 changes: 2 additions & 2 deletions envergo/evaluations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def confirm_request_to_requester(request_id, host):
)

email = EmailMultiAlternatives(
subject="[EnvErgo] Votre demande d'évaluation manuelle",
subject="[EnvErgo] Votre demande d'avis réglementaire",
body=txt_body,
from_email=settings.DEFAULT_FROM_EMAIL,
to=user_emails,
Expand All @@ -80,7 +80,7 @@ def confirm_request_to_requester(request_id, host):
def share_evaluation_by_email(evaluation_reference, host, sender_id, emails):
user = User.objects.get(id=sender_id)
evaluation = Evaluation.objects.get(reference=evaluation_reference)
subject = "[EnvErgo] Évaluation Loi sur l'eau"
subject = "[EnvErgo] Simulation réglementaire"
url = reverse("evaluation_detail", args=[evaluation_reference])
evaluation_url = f"https://{host}{url}?utm_medium=email"

Expand Down
4 changes: 2 additions & 2 deletions envergo/evaluations/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_create_eval_from_request(client, admin_user, eval_request):
data = {"action": "make_evaluation", "_selected_action": eval_request.id}

res = client.post(url, data=data, follow=True)
assert "La nouvelle évaluation a été créée" in res.content.decode()
assert "Le nouvel avis réglementaire a été créé" in res.content.decode()
assert qs.count() == 1

eval = qs[0]
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_create_eval_fails_when_it_already_exists(client, admin_user, eval_reque

res = client.post(url, data=data, follow=True)
assert (
"Cette demande est déjà associée avec une évaluation existante"
"Cette demande est déjà associée avec un avis réglementaire existant"
in res.content.decode()
)
assert qs.count() == 1
Expand Down
13 changes: 8 additions & 5 deletions envergo/evaluations/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def test_searching_inexisting_eval(client):
assert res.status_code == 404

content = res.content.decode("utf-8")
assert "l'évaluation EnvErgo n'est pas encore disponible pour ce projet" in content
assert (
"l'avis réglementaire correspondant à cette référence est introuvable"
in content
)


def test_search_existing_eval(client, evaluation):
Expand Down Expand Up @@ -168,8 +171,8 @@ def test_dashboard_displays_empty_messages(user, client):
res = client.get(dashboard_url)

assert res.status_code == 200
assert "aucune demande d'évaluation en attente" in res.content.decode()
assert "aucune évaluation disponible pour l'instant" in res.content.decode()
assert "aucune demande d'avis réglementaire en attente" in res.content.decode()
assert "aucun avis réglementaire disponible pour l'instant" in res.content.decode()


def test_dashboard_lists_requests_and_evals(user, client):
Expand Down Expand Up @@ -220,7 +223,7 @@ def test_share_evaluation_by_email_form_for_anonymous(client, evaluation, mailou
res = client.get(url)
content = res.content.decode()

assert "Partagez cette évaluation" in content
assert "Partagez cet avis réglementaire" in content
assert (
'<button class="fr-btn fr-btn--icon-left fr-fi-mail-line" type="submit">Partager par email</button>'
not in content
Expand All @@ -244,7 +247,7 @@ def test_share_evaluation_by_email_form(client, user, evaluation, mailoutbox):
res = client.get(url)
content = res.content.decode()

assert "Partagez cette évaluation" in content
assert "Partagez cet avis réglementaire" in content
assert (
'<button class="fr-btn fr-btn--icon-left fr-fi-mail-line" type="submit">Partager par email</button>'
in content
Expand Down
25 changes: 20 additions & 5 deletions envergo/moulinette/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,17 @@ def __init__(self, data, raw_data):
if hasattr(self.department, "moulinette_config"):
self.catalog["config"] = self.department.moulinette_config

self.perimeters = self.get_perimeters()
self.criteria = self.get_criteria()
self.regulations = self.get_regulations()
self.evaluate()

log_data = {
"raw_data": self.raw_data,
"result": self.result(),
}
logger.info(log_data)

def evaluate(self):
for regulation in self.regulations:
regulation.evaluate(self)
Expand Down Expand Up @@ -606,9 +614,7 @@ def flood_zones_filter(zone):

return catalog

def get_regulations(self):
"""Find the activated regulations and their criteria."""

def get_criteria(self):
coords = self.catalog["coords"]

criteria = (
Expand All @@ -631,6 +637,10 @@ def get_regulations(self):
.order_by("weight")
.select_related("activation_map")
)
return criteria

def get_perimeters(self):
coords = self.catalog["coords"]

perimeters = (
Perimeter.objects.filter(
Expand All @@ -652,11 +662,16 @@ def get_regulations(self):
.select_related("activation_map")
)

return perimeters

def get_regulations(self):
"""Find the activated regulations and their criteria."""

regulations = (
Regulation.objects.all()
.order_by("weight")
.prefetch_related(Prefetch("criteria", queryset=criteria))
.prefetch_related(Prefetch("perimeters", queryset=perimeters))
.prefetch_related(Prefetch("criteria", queryset=self.criteria))
.prefetch_related(Prefetch("perimeters", queryset=self.perimeters))
)
return regulations

Expand Down
4 changes: 2 additions & 2 deletions envergo/moulinette/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
pytestmark = pytest.mark.django_db


HOME_TITLE = "Évaluez à quelles réglementations votre projet de construction est soumis"
RESULT_TITLE = "Réglementations environnementales : évaluation personnalisée"
HOME_TITLE = "À quelles réglementations environnementales votre projet de construction est-il soumis ?"
RESULT_TITLE = "Simulation réglementaire du projet"
FORM_ERROR = (
"Nous n'avons pas pu traiter votre demande car le formulaire contient des erreurs."
)
Expand Down
6 changes: 5 additions & 1 deletion envergo/moulinette/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ def get_context_data(self, **kwargs):
# In the debug page, we want to factorize the maps we display, so we order them
# by map first
context["grouped_perimeters"] = moulinette.perimeters.order_by(
"map__name",
"activation_map__name",
"distance",
)
context["grouped_criteria"] = moulinette.criteria.order_by(
"activation_map__name",
"distance",
)
context["grouped_zones"] = (
Expand Down
10 changes: 5 additions & 5 deletions envergo/pages/templatetags/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def sidemenu_item(context, route, label):

@register.simple_tag(takes_context=True)
def evalreq_menu(context):
"""Generate html for the "Demander une évaluation" collapsible menu."""
"""Generate html for the "Services urbanisme" collapsible menu."""

link_route = "request_evaluation"
link_label = "Demander une évaluation manuelle"
link_label = "📍 Services urbanisme"
subroutes = [
"request_eval_wizard_step_1",
"request_eval_wizard_step_2",
Expand All @@ -87,15 +87,15 @@ def faq_menu(context):

@register.simple_tag(takes_context=True)
def evaluation_menu(context):
"""Generate html for the "Mes évaluations" collapsible menu."""
"""Generate html for the "Mes avis réglementaires" collapsible menu."""

try:
current_route = context.request.resolver_match.url_name
except AttributeError:
current_route = ""

links = (
("evaluation_search", "Retrouver une évaluation"),
("evaluation_search", "Retrouver un avis"),
("dashboard", "Tableau de bord"),
)
links_html = [nav_link(url, label, url == current_route) for url, label in links]
Expand All @@ -110,7 +110,7 @@ def evaluation_menu(context):
aria_current = 'aria-current="page"' if current_route in all_routes else ""
menu_html = f"""
<button class="fr-nav__btn" aria-expanded="false" aria-controls="menu-evaluations" {aria_current}>
Mes évaluations
Mes avis réglementaires
</button>
<div class="fr-collapse fr-menu" id="menu-evaluations">
<ul class="fr-menu__list">
Expand Down
Loading

0 comments on commit 8741d12

Please sign in to comment.