Skip to content

Commit

Permalink
Merge pull request #227 from MTES-MCT/misc
Browse files Browse the repository at this point in the history
Diverses améliorations mineures
  • Loading branch information
thibault authored Aug 25, 2023
2 parents 576b35f + 91b684c commit ad46724
Show file tree
Hide file tree
Showing 32 changed files with 778 additions and 9,554 deletions.
8 changes: 4 additions & 4 deletions envergo/analytics/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def __init__(self, *args, **kwargs):
class FeedbackFormUseful(FeedbackForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["message"].label = "En quoi cette évaluation vous est-elle utile ?"
self.fields["message"].widget.attrs[
"placeholder"
] = "Une information nouvelle ? Une procédure clarifiée ? Une décision facilitée ?"
self.fields[
"message"
].label = "Une chose que nous pourrions tout de même améliorer ?"
self.fields["message"].widget.attrs["placeholder"] = ""


class FeedbackFormUseless(FeedbackForm):
Expand Down
26 changes: 19 additions & 7 deletions envergo/evaluations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.conf import settings
from django.contrib import admin, messages
from django.contrib.admin.utils import unquote
from django.contrib.postgres.forms import SimpleArrayField
from django.contrib.sites.models import Site
from django.http import HttpResponseRedirect, QueryDict
from django.template.loader import render_to_string
Expand All @@ -25,6 +26,12 @@


class EvaluationAdminForm(EvaluationFormMixin, forms.ModelForm):
contact_emails = SimpleArrayField(
forms.EmailField(),
label=_("Urbanism department email address(es)"),
error_messages={"item_invalid": _("The %(nth)s address is invalid:")},
widget=admin.widgets.AdminTextareaWidget(attrs={"rows": 3}),
)
reference = forms.CharField(
label=_("Reference"),
help_text=_("If you select an existing request, this value will be replaced."),
Expand Down Expand Up @@ -116,7 +123,7 @@ class Media:
"has_moulinette_url",
"application_number",
"result",
"contact_email",
"contact_emails",
"request_link",
]
form = EvaluationAdminForm
Expand All @@ -126,7 +133,7 @@ class Media:
search_fields = [
"reference",
"application_number",
"contact_email",
"contact_emails",
]

fieldsets = (
Expand All @@ -136,7 +143,7 @@ class Media:
"fields": (
"reference",
"moulinette_url",
"contact_email",
"contact_emails",
"request",
"application_number",
"evaluation_file",
Expand Down Expand Up @@ -278,9 +285,10 @@ class RequestFileInline(admin.TabularInline):
class RequestAdminForm(forms.ModelForm):
class Meta:
widgets = {
"contact_emails": admin.widgets.AdminTextareaWidget(attrs={"rows": 3}),
"project_sponsor_emails": admin.widgets.AdminTextareaWidget(
attrs={"rows": 3}
)
),
}


Expand All @@ -293,7 +301,7 @@ class RequestAdmin(admin.ModelAdmin):
"has_moulinette_url",
"application_number",
"user_type",
"contact_email",
"contact_emails",
"project_sponsor_phone_number",
"evaluation_link",
]
Expand All @@ -306,7 +314,11 @@ class RequestAdmin(admin.ModelAdmin):
"parcels_geojson",
]
inlines = [ParcelInline, RequestFileInline]
search_fields = ["reference", "application_number", "contact_email"]
search_fields = [
"reference",
"application_number",
"contact_emails",
]
ordering = ["-created_at"]
fieldsets = (
(None, {"fields": ("reference", "moulinette_url", "summary")}),
Expand All @@ -331,7 +343,7 @@ class RequestAdmin(admin.ModelAdmin):
{
"fields": (
"user_type",
"contact_email",
"contact_emails",
"project_sponsor_emails",
"project_sponsor_phone_number",
"send_eval_to_sponsor",
Expand Down
24 changes: 14 additions & 10 deletions envergo/evaluations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,17 @@ def clean(self):


class WizardContactForm(forms.ModelForm):

user_type = forms.ChoiceField(
label="Vous êtes :",
required=True,
choices=USER_TYPES,
initial=USER_TYPES.instructor,
widget=forms.RadioSelect,
)
contact_email = forms.EmailField(
label=_("Urbanism department email"), help_text=_("Project instructor…")
contact_emails = SimpleArrayField(
forms.EmailField(),
label=_("Urbanism department email address(es)"),
error_messages={"item_invalid": _("The %(nth)s address is invalid:")},
)
project_sponsor_emails = SimpleArrayField(
forms.EmailField(),
Expand All @@ -111,13 +112,16 @@ class Meta:
model = Request
fields = [
"user_type",
"contact_email",
"contact_emails",
"project_sponsor_emails",
"send_eval_to_sponsor",
]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["contact_emails"].widget.attrs["placeholder"] = _(
"Provide one or several addresses separated by commas « , »"
)
self.fields["project_sponsor_emails"].widget.attrs["placeholder"] = _(
"Provide one or several addresses separated by commas « , »"
)
Expand All @@ -134,11 +138,11 @@ def clean(self):
data = super().clean()
user_type = data.get("user_type", None)
if user_type == USER_TYPES.petitioner:
self.fields["contact_email"].required = False
if "contact_email" in self._errors:
del self._errors["contact_email"]
if "contact_email" in data:
del data["contact_email"]
self.fields["contact_emails"].required = False
if "contact_emails" in self._errors:
del self._errors["contact_emails"]
if "contact_emails" in data:
del data["contact_emails"]

return data

Expand Down Expand Up @@ -168,7 +172,7 @@ class Meta:
"application_number",
"project_description",
"user_type",
"contact_email",
"contact_emails",
"project_sponsor_emails",
"project_sponsor_phone_number",
"send_eval_to_sponsor",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2 on 2023-08-22 07:25

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("evaluations", "0003_rename_rr_mention_evaluation_rr_mention_html_and_more"),
]

operations = [
migrations.AddField(
model_name="request",
name="contact_emails",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.EmailField(max_length=254),
blank=True,
default=list,
size=None,
verbose_name="Contact e-mails",
),
),
migrations.AlterField(
model_name="evaluation",
name="rr_mention_md",
field=models.TextField(
blank=True,
help_text="Will be included in the RR email. Only simple markdown (bold, italic, links, newlines).",
verbose_name="Regulatory reminder mention",
),
),
]
24 changes: 24 additions & 0 deletions envergo/evaluations/migrations/0005_evaluation_contact_emails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2 on 2023-08-22 07:37

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("evaluations", "0004_request_contact_emails_and_more"),
]

operations = [
migrations.AddField(
model_name="evaluation",
name="contact_emails",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.EmailField(max_length=254),
default=list,
size=None,
verbose_name="Contact e-mails",
),
preserve_default=False,
),
]
25 changes: 25 additions & 0 deletions envergo/evaluations/migrations/0006_set_contact_emails_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2 on 2023-08-22 07:40

from django.db import migrations


def set_contact_emails(apps, schema_editor):
Request = apps.get_model("evaluations", "Request")
for request in Request.objects.all():
if request.contact_email:
request.contact_emails = [request.contact_email]
request.save()

Evaluation = apps.get_model("evaluations", "Evaluation")
for evaluation in Evaluation.objects.all():
if evaluation.contact_email:
evaluation.contact_emails = [evaluation.contact_email]
evaluation.save()


class Migration(migrations.Migration):
dependencies = [
("evaluations", "0005_evaluation_contact_emails"),
]

operations = [migrations.RunPython(set_contact_emails)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2 on 2023-08-22 08:41

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("evaluations", "0006_set_contact_emails_values"),
]

operations = [
migrations.RemoveField(
model_name="evaluation",
name="contact_email",
),
migrations.RemoveField(
model_name="request",
name="contact_email",
),
]
22 changes: 15 additions & 7 deletions envergo/evaluations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ class Evaluation(models.Model):
unique=True,
db_index=True,
)
contact_email = models.EmailField(_("E-mail"))
contact_emails = ArrayField(
models.EmailField(), verbose_name=_("Urbanism department email address(es)")
)

request = models.OneToOneField(
"evaluations.Request",
verbose_name=_("Request"),
Expand Down Expand Up @@ -266,18 +269,18 @@ def get_regulatory_reminder_email(self, request):
if evalreq.send_eval_to_sponsor:
if result in ("interdit", "soumis"):
recipients = evalreq.project_sponsor_emails
cc_recipients = [evalreq.contact_email]
cc_recipients = evalreq.contact_emails
if config and config.ddtm_contact_email:
bcc_recipients = [config.ddtm_contact_email]
elif result == "action_requise":
recipients = evalreq.project_sponsor_emails
cc_recipients = [evalreq.contact_email]
cc_recipients = evalreq.contact_emails
else:
recipients = [evalreq.contact_email]
recipients = evalreq.contact_emails
cc_recipients = []

else:
recipients = [evalreq.contact_email]
recipients = evalreq.contact_emails
cc_recipients = []

else:
Expand Down Expand Up @@ -451,7 +454,12 @@ class Request(models.Model):
max_length=32,
verbose_name=_("Who are you?"),
)
contact_email = models.EmailField(_("E-mail"), blank=True)
contact_emails = ArrayField(
models.EmailField(),
blank=True,
default=list,
verbose_name=_("Urbanism department email address(es)"),
)

# TODO rename the inexact word "sponsor"
project_sponsor_emails = ArrayField(
Expand Down Expand Up @@ -531,7 +539,7 @@ def create_evaluation(self):
evaluation = Evaluation.objects.create(
reference=self.reference,
moulinette_url=self.moulinette_url,
contact_email=self.contact_email,
contact_emails=self.contact_emails,
request=self,
application_number=self.application_number,
address=self.address,
Expand Down
4 changes: 2 additions & 2 deletions envergo/evaluations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def post_request_to_notion(request_id, host):
@app.task
def confirm_request_to_requester(request_id, host):
request = Request.objects.filter(id=request_id).first()
user_email = request.contact_email
user_emails = request.contact_emails
faq_url = reverse("faq")
contact_url = reverse("contact_us")
file_upload_url = reverse("request_eval_wizard_step_3", args=[request.reference])
Expand All @@ -69,7 +69,7 @@ def confirm_request_to_requester(request_id, host):
subject="[EnvErgo] Suspension temporaire des services EnvErgo jusqu'au 28 août",
body=txt_body,
from_email=settings.DEFAULT_FROM_EMAIL,
to=[user_email],
to=user_emails,
bcc=[settings.DEFAULT_FROM_EMAIL],
)
email.attach_alternative(html_body, "text/html")
Expand Down
6 changes: 4 additions & 2 deletions envergo/evaluations/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class EvaluationFactory(DjangoModelFactory):
class Meta:
model = Evaluation
skip_postgeneration_save = True

application_number = factory.Sequence(lambda n: f"PC05112321D{n:04}")
evaluation_file = factory.django.FileField(filename="eval.pdf", data=b"Hello")
Expand All @@ -17,7 +18,7 @@ class Meta:
created_surface = fuzzy.FuzzyInteger(25, 9999)
existing_surface = fuzzy.FuzzyInteger(25, 9999)
result = "soumis"
contact_email = "instructor@example.org"
contact_emails = ["instructor@example.org"]
contact_md = "envergo@example.org"
contact_html = "envergo@example.org"

Expand Down Expand Up @@ -48,14 +49,15 @@ class Meta:
class RequestFactory(DjangoModelFactory):
class Meta:
model = Request
skip_postgeneration_save = True

reference = factory.Sequence(lambda n: f"ABC{n:03}")
address = factory.Sequence(lambda n: f"{n} rue de l'example, Testville")
created_surface = fuzzy.FuzzyInteger(25, 10000)
existing_surface = fuzzy.FuzzyInteger(25, 9999)
project_description = factory.Faker("text")
user_type = "instructor"
contact_email = "instructor@example.org"
contact_emails = ["instructor@example.org"]
project_sponsor_emails = ["sponsor1@example.org", "sponsor2@example.org"]

@factory.post_generation
Expand Down
Loading

0 comments on commit ad46724

Please sign in to comment.