Skip to content

Commit

Permalink
Prevent conflict between addresses fields
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Oct 2, 2023
1 parent ce2ae89 commit 56cfaa1
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions envergo/evaluations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,6 @@
class EvaluationFormMixin(forms.Form):
"""Common code for all evaluation forms."""

# We don't set `maxlength` to 15 because we want to allow copy-pasting
# values with spaces
application_number = forms.CharField(
label=_("Application number"),
help_text="15 caractères commençant par « PA », « PC », « DP » ou « CU »",
max_length=64,
)
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(),
label=_("Project sponsor email address(es)"),
help_text=_("Petitioner, project manager…"),
error_messages={"item_invalid": _("The %(nth)s address is invalid:")},
)

def clean_application_number(self):
dirty_number = self.cleaned_data.get("application_number")
if dirty_number == "":
Expand Down Expand Up @@ -86,8 +67,8 @@ class WizardAddressForm(EvaluationFormMixin, forms.ModelForm):
)

class Meta:
fields = ["application_number", "address", "project_description"]
model = Request
fields = ["address", "no_address", "application_number", "project_description"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -105,6 +86,15 @@ def clean(self):
if "address" in self._errors:
del self._errors["address"]

address = data.get("address", None)
if address:
self.add_error(
"no_address",
_(
"You checked this box but still provided an address. Please check your submission."
),
)

return data


Expand All @@ -116,6 +106,17 @@ class WizardContactForm(EvaluationFormMixin, forms.ModelForm):
initial=USER_TYPES.instructor,
widget=forms.RadioSelect,
)
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(),
label=_("Project sponsor email address(es)"),
help_text=_("Petitioner, project manager…"),
error_messages={"item_invalid": _("The %(nth)s address is invalid:")},
)
project_sponsor_phone_number = PhoneNumberField(
label=_("Project sponsor phone number"), region="FR"
)
Expand All @@ -134,6 +135,7 @@ class Meta:
"user_type",
"contact_emails",
"project_sponsor_emails",
"project_sponsor_phone_number",
"send_eval_to_sponsor",
]

Expand Down

0 comments on commit 56cfaa1

Please sign in to comment.