ajustement formulaires

This commit is contained in:
Arthur ZHU 2022-02-28 18:57:05 +01:00
parent 46eb1185d6
commit 842f73d692
9 changed files with 84 additions and 53 deletions

View File

@ -65,20 +65,20 @@ def _build_string_field(label, required=True, render_kw=None):
class EntrepriseCreationForm(FlaskForm): class EntrepriseCreationForm(FlaskForm):
siret = _build_string_field( siret = _build_string_field(
"SIRET", "SIRET (*)",
render_kw={"placeholder": "Numéro composé de 14 chiffres", "maxlength": "14"}, render_kw={"placeholder": "Numéro composé de 14 chiffres", "maxlength": "14"},
) )
nom_entreprise = _build_string_field("Nom de l'entreprise") nom_entreprise = _build_string_field("Nom de l'entreprise (*)")
adresse = _build_string_field("Adresse de l'entreprise") adresse = _build_string_field("Adresse de l'entreprise (*)")
codepostal = _build_string_field("Code postal de l'entreprise") codepostal = _build_string_field("Code postal de l'entreprise (*)")
ville = _build_string_field("Ville de l'entreprise") ville = _build_string_field("Ville de l'entreprise (*)")
pays = _build_string_field("Pays de l'entreprise") pays = _build_string_field("Pays de l'entreprise", required=False)
nom_contact = _build_string_field("Nom du contact") nom_contact = _build_string_field("Nom du contact (*)")
prenom_contact = _build_string_field("Prénom du contact") prenom_contact = _build_string_field("Prénom du contact (*)")
telephone = _build_string_field("Téléphone du contact", required=False) telephone = _build_string_field("Téléphone du contact (*)", required=False)
mail = StringField( mail = StringField(
"Mail du contact", "Mail du contact (*)",
validators=[Optional(), Email(message="Adresse e-mail invalide")], validators=[Optional(), Email(message="Adresse e-mail invalide")],
) )
poste = _build_string_field("Poste du contact", required=False) poste = _build_string_field("Poste du contact", required=False)
@ -121,14 +121,22 @@ class EntrepriseCreationForm(FlaskForm):
class EntrepriseModificationForm(FlaskForm): class EntrepriseModificationForm(FlaskForm):
siret = StringField("SIRET", render_kw={"disabled": ""}) hidden_entreprise_siret = HiddenField()
nom = _build_string_field("Nom de l'entreprise") siret = StringField("SIRET (*)")
adresse = _build_string_field("Adresse") nom = _build_string_field("Nom de l'entreprise (*)")
codepostal = _build_string_field("Code postal") adresse = _build_string_field("Adresse (*)")
ville = _build_string_field("Ville") codepostal = _build_string_field("Code postal (*)")
pays = _build_string_field("Pays") ville = _build_string_field("Ville (*)")
pays = _build_string_field("Pays", required=False)
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.siret.render_kw = {
"disabled": "",
"value": self.hidden_entreprise_siret.data,
}
class MultiCheckboxField(SelectMultipleField): class MultiCheckboxField(SelectMultipleField):
widget = ListWidget(prefix_label=False) widget = ListWidget(prefix_label=False)
@ -136,22 +144,22 @@ class MultiCheckboxField(SelectMultipleField):
class OffreCreationForm(FlaskForm): class OffreCreationForm(FlaskForm):
intitule = _build_string_field("Intitulé") intitule = _build_string_field("Intitulé (*)")
description = TextAreaField( description = TextAreaField(
"Description", validators=[DataRequired(message=CHAMP_REQUIS)] "Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
) )
type_offre = SelectField( type_offre = SelectField(
"Type de l'offre", "Type de l'offre (*)",
choices=[("Stage"), ("Alternance")], choices=[("Stage"), ("Alternance")],
validators=[DataRequired(message=CHAMP_REQUIS)], validators=[DataRequired(message=CHAMP_REQUIS)],
) )
missions = TextAreaField( missions = TextAreaField(
"Missions", validators=[DataRequired(message=CHAMP_REQUIS)] "Missions (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
) )
duree = _build_string_field("Durée") duree = _build_string_field("Durée (*)")
depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
expiration_date = DateField( expiration_date = DateField(
"Date expiration", validators=[DataRequired(message=CHAMP_REQUIS)] "Date expiration (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
) )
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
@ -164,22 +172,22 @@ class OffreCreationForm(FlaskForm):
class OffreModificationForm(FlaskForm): class OffreModificationForm(FlaskForm):
intitule = _build_string_field("Intitulé") intitule = _build_string_field("Intitulé (*)")
description = TextAreaField( description = TextAreaField(
"Description", validators=[DataRequired(message=CHAMP_REQUIS)] "Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
) )
type_offre = SelectField( type_offre = SelectField(
"Type de l'offre", "Type de l'offre (*)",
choices=[("Stage"), ("Alternance")], choices=[("Stage"), ("Alternance")],
validators=[DataRequired(message=CHAMP_REQUIS)], validators=[DataRequired(message=CHAMP_REQUIS)],
) )
missions = TextAreaField( missions = TextAreaField(
"Missions", validators=[DataRequired(message=CHAMP_REQUIS)] "Missions (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
) )
duree = _build_string_field("Durée") duree = _build_string_field("Durée (*)")
depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
expiration_date = DateField( expiration_date = DateField(
"Date expiration", validators=[DataRequired(message=CHAMP_REQUIS)] "Date expiration (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
) )
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
@ -193,11 +201,11 @@ class OffreModificationForm(FlaskForm):
class ContactCreationForm(FlaskForm): class ContactCreationForm(FlaskForm):
hidden_entreprise_id = HiddenField() hidden_entreprise_id = HiddenField()
nom = _build_string_field("Nom") nom = _build_string_field("Nom (*)")
prenom = _build_string_field("Prénom") prenom = _build_string_field("Prénom (*)")
telephone = _build_string_field("Téléphone", required=False) telephone = _build_string_field("Téléphone (*)", required=False)
mail = StringField( mail = StringField(
"Mail", "Mail (*)",
validators=[Optional(), Email(message="Adresse e-mail invalide")], validators=[Optional(), Email(message="Adresse e-mail invalide")],
) )
poste = _build_string_field("Poste", required=False) poste = _build_string_field("Poste", required=False)
@ -232,11 +240,11 @@ class ContactCreationForm(FlaskForm):
class ContactModificationForm(FlaskForm): class ContactModificationForm(FlaskForm):
hidden_contact_id = HiddenField() hidden_contact_id = HiddenField()
hidden_entreprise_id = HiddenField() hidden_entreprise_id = HiddenField()
nom = _build_string_field("Nom") nom = _build_string_field("Nom (*)")
prenom = _build_string_field("Prénom") prenom = _build_string_field("Prénom (*)")
telephone = _build_string_field("Téléphone", required=False) telephone = _build_string_field("Téléphone (*)", required=False)
mail = StringField( mail = StringField(
"Mail", "Mail (*)",
validators=[Optional(), Email(message="Adresse e-mail invalide")], validators=[Optional(), Email(message="Adresse e-mail invalide")],
) )
poste = _build_string_field("Poste", required=False) poste = _build_string_field("Poste", required=False)
@ -271,18 +279,20 @@ class ContactModificationForm(FlaskForm):
class HistoriqueCreationForm(FlaskForm): class HistoriqueCreationForm(FlaskForm):
etudiant = _build_string_field( etudiant = _build_string_field(
"Étudiant", "Étudiant (*)",
render_kw={"placeholder": "Tapez le nom de l'étudiant"}, render_kw={"placeholder": "Tapez le nom de l'étudiant"},
) )
type_offre = SelectField( type_offre = SelectField(
"Type de l'offre", "Type de l'offre (*)",
choices=[("Stage"), ("Alternance")], choices=[("Stage"), ("Alternance")],
validators=[DataRequired(message=CHAMP_REQUIS)], validators=[DataRequired(message=CHAMP_REQUIS)],
) )
date_debut = DateField( date_debut = DateField(
"Date début", validators=[DataRequired(message=CHAMP_REQUIS)] "Date début (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
)
date_fin = DateField(
"Date fin (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
) )
date_fin = DateField("Date fin", validators=[DataRequired(message=CHAMP_REQUIS)])
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
def validate(self): def validate(self):
@ -315,7 +325,7 @@ class HistoriqueCreationForm(FlaskForm):
class EnvoiOffreForm(FlaskForm): class EnvoiOffreForm(FlaskForm):
responsable = _build_string_field( responsable = _build_string_field(
"Responsable de formation", "Responsable de formation (*)",
render_kw={"placeholder": "Tapez le nom du responsable de formation"}, render_kw={"placeholder": "Tapez le nom du responsable de formation"},
) )
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
@ -336,7 +346,7 @@ class EnvoiOffreForm(FlaskForm):
class AjoutFichierForm(FlaskForm): class AjoutFichierForm(FlaskForm):
fichier = FileField( fichier = FileField(
"Fichier", "Fichier (*)",
validators=[ validators=[
FileRequired(message=CHAMP_REQUIS), FileRequired(message=CHAMP_REQUIS),
FileAllowed(["pdf", "docx"], "Fichier .pdf ou .docx uniquement"), FileAllowed(["pdf", "docx"], "Fichier .pdf ou .docx uniquement"),
@ -355,7 +365,7 @@ class ValidationConfirmationForm(FlaskForm):
class ImportForm(FlaskForm): class ImportForm(FlaskForm):
fichier = FileField( fichier = FileField(
"Fichier", "Fichier (*)",
validators=[ validators=[
FileRequired(message=CHAMP_REQUIS), FileRequired(message=CHAMP_REQUIS),
FileAllowed(["xlsx"], "Fichier .xlsx uniquement"), FileAllowed(["xlsx"], "Fichier .xlsx uniquement"),

View File

@ -275,7 +275,7 @@ def add_entreprise():
adresse=form.adresse.data.strip(), adresse=form.adresse.data.strip(),
codepostal=form.codepostal.data.strip(), codepostal=form.codepostal.data.strip(),
ville=form.ville.data.strip(), ville=form.ville.data.strip(),
pays=form.pays.data.strip(), pays=form.pays.data.strip() if form.pays.data.strip() else "FRANCE",
) )
db.session.add(entreprise) db.session.add(entreprise)
db.session.commit() db.session.commit()
@ -326,7 +326,7 @@ def edit_entreprise(id):
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404( entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
description=f"entreprise {id} inconnue" description=f"entreprise {id} inconnue"
) )
form = EntrepriseModificationForm() form = EntrepriseModificationForm(hidden_entreprise_siret=entreprise.siret)
if form.validate_on_submit(): if form.validate_on_submit():
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{form.nom.data.strip()}</a>" nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{form.nom.data.strip()}</a>"
if entreprise.nom != form.nom.data.strip(): if entreprise.nom != form.nom.data.strip():
@ -361,13 +361,15 @@ def edit_entreprise(id):
) )
entreprise.ville = form.ville.data.strip() entreprise.ville = form.ville.data.strip()
db.session.add(log) db.session.add(log)
if entreprise.pays != form.pays.data.strip(): if entreprise.pays != form.pays.data.strip() or not form.pays.data.strip():
log = EntrepriseLog( log = EntrepriseLog(
authenticated_user=current_user.user_name, authenticated_user=current_user.user_name,
object=entreprise.id, object=entreprise.id,
text=f"{nom_entreprise} - Modification du pays (ancien pays: {entreprise.pays})", text=f"{nom_entreprise} - Modification du pays (ancien pays: {entreprise.pays})",
) )
entreprise.pays = form.pays.data.strip() entreprise.pays = (
form.pays.data.strip() if form.pays.data.strip() else "FRANCE"
)
db.session.add(log) db.session.add(log)
db.session.commit() db.session.commit()
flash("L'entreprise a été modifié.") flash("L'entreprise a été modifié.")

View File

@ -8,7 +8,8 @@
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<p> <p>
Les champs s'auto complète selon le SIRET Les champs s'auto complète selon le SIRET<br>
(*) champs requis
</p> </p>
{{ wtf.quick_form(form, novalidate=True) }} {{ wtf.quick_form(form, novalidate=True) }}
</div> </div>

View File

@ -13,6 +13,9 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<p>
(*) champs requis
</p>
{{ wtf.quick_form(form, novalidate=True) }} {{ wtf.quick_form(form, novalidate=True) }}
</div> </div>
</div> </div>

View File

@ -13,6 +13,9 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<p>
(*) champs requis
</p>
{{ wtf.quick_form(form, novalidate=True) }} {{ wtf.quick_form(form, novalidate=True) }}
</div> </div>
</div> </div>

View File

@ -11,6 +11,9 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<p>
(*) champs requis
</p>
{{ wtf.quick_form(form, novalidate=True) }} {{ wtf.quick_form(form, novalidate=True) }}
</div> </div>
</div> </div>

View File

@ -11,6 +11,9 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<p>
(*) champs requis
</p>
{{ wtf.quick_form(form, novalidate=True) }} {{ wtf.quick_form(form, novalidate=True) }}
</div> </div>

View File

@ -15,6 +15,9 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<p>
(*) champs requis
</p>
{{ wtf.quick_form(form, novalidate=True) }} {{ wtf.quick_form(form, novalidate=True) }}
</div> </div>
</div> </div>

View File

@ -15,6 +15,9 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<p>
(*) champs requis
</p>
{{ wtf.quick_form(form, novalidate=True) }} {{ wtf.quick_form(form, novalidate=True) }}
</div> </div>
</div> </div>