diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 3ab5fb1f8..67a600256 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -40,6 +40,7 @@ from wtforms import ( SelectMultipleField, DateField, BooleanField, + FieldList, ) from wtforms.validators import ValidationError, DataRequired, Email, Optional from wtforms.widgets import ListWidget, CheckboxInput @@ -424,19 +425,13 @@ class StageApprentissageModificationForm(FlaskForm): class EnvoiOffreForm(FlaskForm): - responsable_1 = _build_string_field( - "Responsable de formation (*)", - render_kw={"placeholder": "Tapez le nom du responsable de formation"}, - ) - responsable_2 = _build_string_field( - "Responsable de formation", - required=False, - render_kw={"placeholder": "Tapez le nom du responsable de formation"}, - ) - responsable_3 = _build_string_field( - "Responsable de formation", - required=False, - render_kw={"placeholder": "Tapez le nom du responsable de formation"}, + responsables = FieldList( + _build_string_field( + "Responsable (*)", + render_kw={"placeholder": "Tapez le nom du responsable de formation"}, + ), + min_entries=1, + max_entries=5, ) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) @@ -445,12 +440,9 @@ class EnvoiOffreForm(FlaskForm): if not FlaskForm.validate(self): validate = False - for field in self: - if ( - field.name in ["responsable_1", "responsable_2", "responsable_3"] - and field.data.strip() - ): - responsable_data = field.data.upper().strip() + for entry in self.responsables.entries: + if entry.data: + responsable_data = entry.data.upper().strip() stm = text( "SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:responsable_data" ) @@ -460,7 +452,7 @@ class EnvoiOffreForm(FlaskForm): .first() ) if responsable is None: - field.errors.append("Champ incorrect (selectionnez dans la liste)") + entry.errors.append("Champ incorrect (selectionnez dans la liste)") validate = False return validate diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 30ae040f6..bf78bd5a9 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -987,12 +987,9 @@ def envoyer_offre(id): ) form = EnvoiOffreForm() if form.validate_on_submit(): - for field in form: - if ( - field.name in ["responsable_1", "responsable_2", "responsable_3"] - and field.data - ): - responsable_data = field.data.upper().strip() + for responsable in form.responsables.entries: + if responsable.data.strip(): + responsable_data = responsable.data.upper().strip() stm = text( "SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:responsable_data" ) diff --git a/app/templates/entreprises/contacts.html b/app/templates/entreprises/contacts.html index cb01d4ed1..2896627e5 100644 --- a/app/templates/entreprises/contacts.html +++ b/app/templates/entreprises/contacts.html @@ -11,7 +11,9 @@ {% block app_content %}