From db19322b0704446d19dcd60808a3e86605f17169 Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Wed, 24 Aug 2022 21:06:11 +0200 Subject: [PATCH] form edit correspondant (champ site) --- app/entreprises/forms.py | 14 ++++++++++++++ app/entreprises/routes.py | 3 +++ 2 files changed, 17 insertions(+) diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index eb160890..44e679f9 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -496,6 +496,7 @@ class CorrespondantsCreationForm(FlaskForm): class CorrespondantModificationForm(FlaskForm): hidden_correspondant_id = HiddenField() hidden_site_id = HiddenField() + hidden_entreprise_id = HiddenField() civilite = SelectField( "Civilité (*)", choices=[("H", "Monsieur"), ("F", "Madame")], @@ -512,9 +513,22 @@ class CorrespondantModificationForm(FlaskForm): service = _build_string_field("Service", required=False) origine = _build_string_field("Origine", required=False) notes = _build_string_field("Notes", required=False) + site = SelectField( + "Site du correspondant", validators=[DataRequired()], description="Nom du site" + ) submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) cancel = SubmitField("Annuler", render_kw=SUBMIT_MARGE) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.site.choices = [ + (site.id, f"{site.nom}") + for site in db.session.query(EntrepriseSite) + .filter(EntrepriseSite.entreprise_id == self.hidden_entreprise_id.data) + .all() + ] + def validate(self): validate = True if not FlaskForm.validate(self): diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index babb5e49..2d419500 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -1189,6 +1189,8 @@ def edit_correspondant(entreprise_id, site_id, correspondant_id): form = CorrespondantModificationForm( hidden_site_id=correspondant.site.id, hidden_correspondant_id=correspondant.id, + hidden_entreprise_id=entreprise_id, + site=correspondant.site_id, ) if request.method == "POST" and form.cancel.data: return redirect( @@ -1204,6 +1206,7 @@ def edit_correspondant(entreprise_id, site_id, correspondant_id): correspondant.service = form.service.data.strip() correspondant.origine = form.origine.data.strip() correspondant.notes = form.notes.data.strip() + correspondant.site_id = form.site.data log = EntrepriseHistorique( authenticated_user=current_user.user_name, entreprise_id=correspondant.site.entreprise.id,