forked from ScoDoc/ScoDoc
refactoring
This commit is contained in:
parent
c7bd3b19c8
commit
0cef1089b3
@ -38,8 +38,8 @@ from wtforms import (
|
||||
SelectField,
|
||||
HiddenField,
|
||||
SelectMultipleField,
|
||||
DateField,
|
||||
)
|
||||
from wtforms.fields import EmailField, DateField
|
||||
from wtforms.validators import ValidationError, DataRequired, Email, Optional
|
||||
from wtforms.widgets import ListWidget, CheckboxInput
|
||||
|
||||
@ -48,65 +48,55 @@ from app.models import Identite, Departement
|
||||
from app.auth.models import User
|
||||
|
||||
CHAMP_REQUIS = "Ce champ est requis"
|
||||
SUBMIT_MARGE = {"style": "margin-bottom: 10px;"}
|
||||
|
||||
|
||||
def _build_string_field(label, required=True, render_kw=None):
|
||||
if required:
|
||||
return StringField(
|
||||
label,
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
render_kw=render_kw,
|
||||
)
|
||||
else:
|
||||
return StringField(label, validators=[Optional()], render_kw=render_kw)
|
||||
|
||||
|
||||
class EntrepriseCreationForm(FlaskForm):
|
||||
siret = StringField(
|
||||
siret = _build_string_field(
|
||||
"SIRET",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
render_kw={"placeholder": "Numéro composé de 14 chiffres", "maxlength": "14"},
|
||||
)
|
||||
nom_entreprise = StringField(
|
||||
"Nom de l'entreprise",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
adresse = StringField(
|
||||
"Adresse de l'entreprise",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
codepostal = StringField(
|
||||
"Code postal de l'entreprise",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
ville = StringField(
|
||||
"Ville de l'entreprise",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
pays = StringField(
|
||||
"Pays de l'entreprise",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
render_kw={"style": "margin-bottom: 50px;"},
|
||||
)
|
||||
nom_entreprise = _build_string_field("Nom de l'entreprise")
|
||||
adresse = _build_string_field("Adresse de l'entreprise")
|
||||
codepostal = _build_string_field("Code postal de l'entreprise")
|
||||
ville = _build_string_field("Ville de l'entreprise")
|
||||
pays = _build_string_field("Pays de l'entreprise")
|
||||
|
||||
nom_contact = StringField(
|
||||
"Nom du contact", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
prenom_contact = StringField(
|
||||
"Prénom du contact",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
telephone = StringField("Téléphone du contact", validators=[Optional()])
|
||||
mail = EmailField(
|
||||
nom_contact = _build_string_field("Nom du contact")
|
||||
prenom_contact = _build_string_field("Prénom du contact")
|
||||
telephone = _build_string_field("Téléphone du contact", required=False)
|
||||
mail = StringField(
|
||||
"Mail du contact",
|
||||
validators=[Optional(), Email(message="Adresse e-mail invalide")],
|
||||
)
|
||||
poste = StringField("Poste du contact", validators=[Optional()])
|
||||
service = StringField("Service du contact", validators=[Optional()])
|
||||
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
||||
poste = _build_string_field("Poste du contact", required=False)
|
||||
service = _build_string_field("Service du contact", required=False)
|
||||
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def validate(self):
|
||||
rv = FlaskForm.validate(self)
|
||||
if not rv:
|
||||
return False
|
||||
validate = True
|
||||
if not FlaskForm.validate(self):
|
||||
validate = False
|
||||
|
||||
if not self.telephone.data and not self.mail.data:
|
||||
self.telephone.errors.append(
|
||||
"Saisir un moyen de contact (mail ou téléphone)"
|
||||
)
|
||||
self.mail.errors.append("Saisir un moyen de contact (mail ou téléphone)")
|
||||
return False
|
||||
validate = False
|
||||
|
||||
return True
|
||||
return validate
|
||||
|
||||
def validate_siret(self, siret):
|
||||
siret = siret.data.strip()
|
||||
@ -126,18 +116,13 @@ class EntrepriseCreationForm(FlaskForm):
|
||||
|
||||
|
||||
class EntrepriseModificationForm(FlaskForm):
|
||||
siret = StringField("SIRET", validators=[], render_kw={"disabled": ""})
|
||||
nom = StringField(
|
||||
"Nom de l'entreprise",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
adresse = StringField("Adresse", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
codepostal = StringField(
|
||||
"Code postal", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
ville = StringField("Ville", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
pays = StringField("Pays", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
|
||||
siret = StringField("SIRET", render_kw={"disabled": ""})
|
||||
nom = _build_string_field("Nom de l'entreprise")
|
||||
adresse = _build_string_field("Adresse")
|
||||
codepostal = _build_string_field("Code postal")
|
||||
ville = _build_string_field("Ville")
|
||||
pays = _build_string_field("Pays")
|
||||
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
|
||||
|
||||
|
||||
class MultiCheckboxField(SelectMultipleField):
|
||||
@ -146,8 +131,7 @@ class MultiCheckboxField(SelectMultipleField):
|
||||
|
||||
|
||||
class OffreCreationForm(FlaskForm):
|
||||
|
||||
intitule = StringField("Intitulé", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
intitule = _build_string_field("Intitulé")
|
||||
description = TextAreaField(
|
||||
"Description", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
@ -156,15 +140,13 @@ class OffreCreationForm(FlaskForm):
|
||||
choices=[("Stage"), ("Alternance")],
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
missions = TextAreaField(
|
||||
"Missions", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
duree = StringField("Durée", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
missions = _build_string_field("Missions")
|
||||
duree = _build_string_field("Durée")
|
||||
depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
|
||||
expiration_date = DateField(
|
||||
"Date expiration", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -175,7 +157,7 @@ class OffreCreationForm(FlaskForm):
|
||||
|
||||
|
||||
class OffreModificationForm(FlaskForm):
|
||||
intitule = StringField("Intitulé", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
intitule = _build_string_field("Intitulé")
|
||||
description = TextAreaField(
|
||||
"Description", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
@ -184,15 +166,13 @@ class OffreModificationForm(FlaskForm):
|
||||
choices=[("Stage"), ("Alternance")],
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
)
|
||||
missions = TextAreaField(
|
||||
"Missions", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
duree = StringField("Durée", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
missions = _build_string_field("Missions")
|
||||
duree = _build_string_field("Durée")
|
||||
depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
|
||||
expiration_date = DateField(
|
||||
"Date expiration", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -204,30 +184,27 @@ class OffreModificationForm(FlaskForm):
|
||||
|
||||
class ContactCreationForm(FlaskForm):
|
||||
hidden_entreprise_id = HiddenField()
|
||||
nom = StringField("Nom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
prenom = StringField("Prénom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
telephone = StringField("Téléphone", validators=[Optional()])
|
||||
mail = EmailField(
|
||||
nom = _build_string_field("Nom")
|
||||
prenom = _build_string_field("Prénom")
|
||||
telephone = _build_string_field("Téléphone", required=False)
|
||||
mail = StringField(
|
||||
"Mail",
|
||||
validators=[Optional(), Email(message="Adresse e-mail invalide")],
|
||||
)
|
||||
poste = StringField("Poste", validators=[Optional()])
|
||||
service = StringField("Service", validators=[Optional()])
|
||||
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
||||
poste = _build_string_field("Poste", required=False)
|
||||
service = _build_string_field("Service", required=False)
|
||||
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def validate(self):
|
||||
rv = FlaskForm.validate(self)
|
||||
if not rv:
|
||||
return False
|
||||
validate = True
|
||||
if not FlaskForm.validate(self):
|
||||
validate = False
|
||||
|
||||
contact = EntrepriseContact.query.filter_by(
|
||||
entreprise_id=self.hidden_entreprise_id.data,
|
||||
nom=self.nom.data,
|
||||
prenom=self.prenom.data,
|
||||
).first()
|
||||
|
||||
validate = True
|
||||
|
||||
if contact is not None:
|
||||
self.nom.errors.append("Ce contact existe déjà (même nom et prénom)")
|
||||
self.prenom.errors.append("")
|
||||
@ -246,21 +223,21 @@ class ContactCreationForm(FlaskForm):
|
||||
class ContactModificationForm(FlaskForm):
|
||||
hidden_contact_id = HiddenField()
|
||||
hidden_entreprise_id = HiddenField()
|
||||
nom = StringField("Nom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
prenom = StringField("Prénom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
telephone = StringField("Téléphone", validators=[Optional()])
|
||||
mail = EmailField(
|
||||
nom = _build_string_field("Nom")
|
||||
prenom = _build_string_field("Prénom")
|
||||
telephone = _build_string_field("Téléphone", required=False)
|
||||
mail = StringField(
|
||||
"Mail",
|
||||
validators=[Optional(), Email(message="Adresse e-mail invalide")],
|
||||
)
|
||||
poste = StringField("Poste", validators=[Optional()])
|
||||
service = StringField("Service", validators=[Optional()])
|
||||
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
|
||||
poste = _build_string_field("Poste", required=False)
|
||||
service = _build_string_field("Service", required=False)
|
||||
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def validate(self):
|
||||
rv = FlaskForm.validate(self)
|
||||
if not rv:
|
||||
return False
|
||||
validate = True
|
||||
if not FlaskForm.validate(self):
|
||||
validate = False
|
||||
|
||||
contact = EntrepriseContact.query.filter(
|
||||
EntrepriseContact.id != self.hidden_contact_id.data,
|
||||
@ -268,9 +245,6 @@ class ContactModificationForm(FlaskForm):
|
||||
EntrepriseContact.nom == self.nom.data,
|
||||
EntrepriseContact.prenom == self.prenom.data,
|
||||
).first()
|
||||
|
||||
validate = True
|
||||
|
||||
if contact is not None:
|
||||
self.nom.errors.append("Ce contact existe déjà (même nom et prénom)")
|
||||
self.prenom.errors.append("")
|
||||
@ -287,10 +261,9 @@ class ContactModificationForm(FlaskForm):
|
||||
|
||||
|
||||
class HistoriqueCreationForm(FlaskForm):
|
||||
etudiant = StringField(
|
||||
etudiant = _build_string_field(
|
||||
"Étudiant",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
render_kw={"placeholder": "Tapez le nom de l'étudiant puis selectionnez"},
|
||||
render_kw={"placeholder": "Tapez le nom de l'étudiant"},
|
||||
)
|
||||
type_offre = SelectField(
|
||||
"Type de l'offre",
|
||||
@ -301,18 +274,23 @@ class HistoriqueCreationForm(FlaskForm):
|
||||
"Date début", validators=[DataRequired(message=CHAMP_REQUIS)]
|
||||
)
|
||||
date_fin = DateField("Date fin", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def validate(self):
|
||||
rv = FlaskForm.validate(self)
|
||||
if not rv:
|
||||
return False
|
||||
validate = True
|
||||
if not FlaskForm.validate(self):
|
||||
validate = False
|
||||
|
||||
if self.date_debut.data > self.date_fin.data:
|
||||
if (
|
||||
self.date_debut.data
|
||||
and self.date_fin.data
|
||||
and self.date_debut.data > self.date_fin.data
|
||||
):
|
||||
self.date_debut.errors.append("Les dates sont incompatibles")
|
||||
self.date_fin.errors.append("Les dates sont incompatibles")
|
||||
return False
|
||||
return True
|
||||
validate = False
|
||||
|
||||
return validate
|
||||
|
||||
def validate_etudiant(self, etudiant):
|
||||
etudiant_data = etudiant.data.upper().strip()
|
||||
@ -327,11 +305,11 @@ class HistoriqueCreationForm(FlaskForm):
|
||||
|
||||
|
||||
class EnvoiOffreForm(FlaskForm):
|
||||
responsable = StringField(
|
||||
responsable = _build_string_field(
|
||||
"Responsable de formation",
|
||||
validators=[DataRequired(message=CHAMP_REQUIS)],
|
||||
render_kw={"placeholder": "Tapez le nom du responsable de formation"},
|
||||
)
|
||||
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def validate_responsable(self, responsable):
|
||||
responsable_data = responsable.data.upper().strip()
|
||||
@ -355,15 +333,15 @@ class AjoutFichierForm(FlaskForm):
|
||||
FileAllowed(["pdf", "docx"], "Fichier .pdf ou .docx uniquement"),
|
||||
],
|
||||
)
|
||||
submit = SubmitField("Ajouter", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Ajouter", render_kw=SUBMIT_MARGE)
|
||||
|
||||
|
||||
class SuppressionConfirmationForm(FlaskForm):
|
||||
submit = SubmitField("Supprimer", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Supprimer", render_kw=SUBMIT_MARGE)
|
||||
|
||||
|
||||
class ValidationConfirmationForm(FlaskForm):
|
||||
submit = SubmitField("Valider", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Valider", render_kw=SUBMIT_MARGE)
|
||||
|
||||
|
||||
class ImportForm(FlaskForm):
|
||||
@ -374,4 +352,4 @@ class ImportForm(FlaskForm):
|
||||
FileAllowed(["xlsx"], "Fichier .xlsx uniquement"),
|
||||
],
|
||||
)
|
||||
submit = SubmitField("Importer", render_kw={"style": "margin-bottom: 10px;"})
|
||||
submit = SubmitField("Importer", render_kw=SUBMIT_MARGE)
|
||||
|
@ -61,7 +61,7 @@ def index():
|
||||
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
|
||||
return render_template(
|
||||
"entreprises/entreprises.html",
|
||||
title=("Entreprises"),
|
||||
title="Entreprises",
|
||||
entreprises=entreprises,
|
||||
logs=logs,
|
||||
)
|
||||
@ -79,7 +79,7 @@ def logs():
|
||||
)
|
||||
return render_template(
|
||||
"entreprises/logs.html",
|
||||
title=("Logs"),
|
||||
title="Logs",
|
||||
logs=logs,
|
||||
)
|
||||
|
||||
@ -93,7 +93,7 @@ def validation():
|
||||
entreprises = Entreprise.query.filter_by(visible=False).all()
|
||||
return render_template(
|
||||
"entreprises/entreprises_validation.html",
|
||||
title=("Validation entreprises"),
|
||||
title="Validation entreprises",
|
||||
entreprises=entreprises,
|
||||
)
|
||||
|
||||
@ -114,7 +114,7 @@ def contacts():
|
||||
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
|
||||
return render_template(
|
||||
"entreprises/contacts.html",
|
||||
title=("Contacts"),
|
||||
title="Contacts",
|
||||
contacts=contacts,
|
||||
logs=logs,
|
||||
)
|
||||
@ -151,9 +151,7 @@ def fiche_entreprise(id):
|
||||
offre_id=offre.id
|
||||
).all()
|
||||
offres_with_files.append([offre, files, offre_depts])
|
||||
contacts = []
|
||||
for contact in entreprise.contacts:
|
||||
contacts.append(contact)
|
||||
contacts = entreprise.contacts[:]
|
||||
logs = (
|
||||
EntrepriseLog.query.order_by(EntrepriseLog.date.desc())
|
||||
.filter_by(object=id)
|
||||
@ -169,7 +167,7 @@ def fiche_entreprise(id):
|
||||
)
|
||||
return render_template(
|
||||
"entreprises/fiche_entreprise.html",
|
||||
title=("Fiche entreprise"),
|
||||
title="Fiche entreprise",
|
||||
entreprise=entreprise,
|
||||
contacts=contacts,
|
||||
offres=offres_with_files,
|
||||
@ -193,7 +191,7 @@ def logs_entreprise(id):
|
||||
)
|
||||
return render_template(
|
||||
"entreprises/logs_entreprise.html",
|
||||
title=("Logs"),
|
||||
title="Logs",
|
||||
logs=logs,
|
||||
entreprise=entreprise,
|
||||
)
|
||||
@ -209,7 +207,7 @@ def fiche_entreprise_validation(id):
|
||||
contacts = entreprise.contacts
|
||||
return render_template(
|
||||
"entreprises/fiche_entreprise_validation.html",
|
||||
title=("Validation fiche entreprise"),
|
||||
title="Validation fiche entreprise",
|
||||
entreprise=entreprise,
|
||||
contacts=contacts,
|
||||
)
|
||||
@ -246,7 +244,7 @@ def offres_recues():
|
||||
offres_recues_with_files.append([offre[0], offre[1], files])
|
||||
return render_template(
|
||||
"entreprises/offres_recues.html",
|
||||
title=("Offres reçues"),
|
||||
title="Offres reçues",
|
||||
offres_recues=offres_recues_with_files,
|
||||
)
|
||||
|
||||
@ -282,7 +280,7 @@ def offres_expirees(id):
|
||||
offres_expirees_with_files.append([offre, files, offre_depts])
|
||||
return render_template(
|
||||
"entreprises/offres_expirees.html",
|
||||
title=("Offres expirées"),
|
||||
title="Offres expirées",
|
||||
entreprise=entreprise,
|
||||
offres_expirees=offres_expirees_with_files,
|
||||
)
|
||||
@ -335,7 +333,7 @@ def add_entreprise():
|
||||
return redirect(url_for("entreprises.index"))
|
||||
return render_template(
|
||||
"entreprises/ajout_entreprise.html",
|
||||
title=("Ajout entreprise avec contact"),
|
||||
title="Ajout entreprise avec contact",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -402,7 +400,7 @@ def edit_entreprise(id):
|
||||
form.pays.data = entreprise.pays
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
title=("Modification entreprise"),
|
||||
title="Modification entreprise",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -436,7 +434,7 @@ def delete_entreprise(id):
|
||||
return redirect(url_for("entreprises.index"))
|
||||
return render_template(
|
||||
"entreprises/delete_confirmation.html",
|
||||
title=("Supression entreprise"),
|
||||
title="Supression entreprise",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -462,7 +460,7 @@ def validate_entreprise(id):
|
||||
return redirect(url_for("entreprises.index"))
|
||||
return render_template(
|
||||
"entreprises/validate_confirmation.html",
|
||||
title=("Validation entreprise"),
|
||||
title="Validation entreprise",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -505,7 +503,7 @@ def add_offre(id):
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
title=("Ajout offre"),
|
||||
title="Ajout offre",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -560,7 +558,7 @@ def edit_offre(id):
|
||||
form.depts.data = offre_depts_list
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
title=("Modification offre"),
|
||||
title="Modification offre",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -595,7 +593,7 @@ def delete_offre(id):
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id))
|
||||
return render_template(
|
||||
"entreprises/delete_confirmation.html",
|
||||
title=("Supression offre"),
|
||||
title="Supression offre",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -630,7 +628,7 @@ def add_contact(id):
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
title=("Ajout contact"),
|
||||
title="Ajout contact",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -673,7 +671,7 @@ def edit_contact(id):
|
||||
form.service.data = contact.service
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
title=("Modification contact"),
|
||||
title="Modification contact",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -685,17 +683,18 @@ def delete_contact(id):
|
||||
Permet de supprimer un contact
|
||||
"""
|
||||
contact = EntrepriseContact.query.filter_by(id=id).first_or_404()
|
||||
entreprise_id = contact.entreprise.id
|
||||
form = SuppressionConfirmationForm()
|
||||
if form.validate_on_submit():
|
||||
contact_count = EntrepriseContact.query.filter_by(
|
||||
entreprise_id=contact.entreprise.id
|
||||
entreprise_id=contact.entreprise_id
|
||||
).count()
|
||||
if contact_count == 1:
|
||||
flash(
|
||||
"Le contact n'a pas été supprimé de la fiche entreprise. (1 contact minimum)"
|
||||
)
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id))
|
||||
return redirect(
|
||||
url_for("entreprises.fiche_entreprise", id=contact.entreprise_id)
|
||||
)
|
||||
else:
|
||||
db.session.delete(contact)
|
||||
log = EntrepriseLog(
|
||||
@ -706,10 +705,12 @@ def delete_contact(id):
|
||||
db.session.add(log)
|
||||
db.session.commit()
|
||||
flash("Le contact a été supprimé de la fiche entreprise.")
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id))
|
||||
return redirect(
|
||||
url_for("entreprises.fiche_entreprise", id=contact.entreprise_id)
|
||||
)
|
||||
return render_template(
|
||||
"entreprises/delete_confirmation.html",
|
||||
title=("Supression contact"),
|
||||
title="Supression contact",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -752,7 +753,7 @@ def add_historique(id):
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
||||
return render_template(
|
||||
"entreprises/ajout_historique.html",
|
||||
title=("Ajout historique"),
|
||||
title="Ajout historique",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -776,7 +777,9 @@ def envoyer_offre(id):
|
||||
.first()
|
||||
)
|
||||
envoi_offre = EntrepriseEnvoiOffre(
|
||||
sender_id=current_user.id, receiver_id=responsable.id, offre_id=offre.id
|
||||
sender_id=current_user.id,
|
||||
receiver_id=responsable.id,
|
||||
offre_id=offre.id,
|
||||
)
|
||||
db.session.add(envoi_offre)
|
||||
db.session.commit()
|
||||
@ -784,7 +787,7 @@ def envoyer_offre(id):
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id))
|
||||
return render_template(
|
||||
"entreprises/envoi_offre_form.html",
|
||||
title=("Envoyer une offre"),
|
||||
title="Envoyer une offre",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -904,10 +907,10 @@ def import_entreprises():
|
||||
"""
|
||||
form = ImportForm()
|
||||
if form.validate_on_submit():
|
||||
path = os.path.join(Config.SCODOC_VAR_DIR, "tmp")
|
||||
file = form.fichier.data
|
||||
filename = secure_filename(file.filename)
|
||||
file_path = os.path.join(path, filename)
|
||||
file_path = os.path.join(
|
||||
Config.SCODOC_VAR_DIR, "tmp", secure_filename(file.filename)
|
||||
)
|
||||
file.save(file_path)
|
||||
data = sco_excel.excel_file_to_list(file_path)
|
||||
os.remove(file_path)
|
||||
@ -919,7 +922,7 @@ def import_entreprises():
|
||||
flash("Veuillez utilisez la feuille excel à remplir")
|
||||
return render_template(
|
||||
"entreprises/import_entreprises.html",
|
||||
title=("Importation entreprises"),
|
||||
title="Importation entreprises",
|
||||
form=form,
|
||||
)
|
||||
for entreprise_data in data[1][1:]:
|
||||
@ -944,7 +947,7 @@ def import_entreprises():
|
||||
flash(f"Erreur lors de l'importation (ligne {ligne})")
|
||||
return render_template(
|
||||
"entreprises/import_entreprises.html",
|
||||
title=("Importation entreprises"),
|
||||
title="Importation entreprises",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -955,7 +958,7 @@ def import_entreprises():
|
||||
flash(f"Importation réussie de {len(entreprises_import)} entreprise(s)")
|
||||
return render_template(
|
||||
"entreprises/import_entreprises.html",
|
||||
title=("Importation entreprises"),
|
||||
title="Importation entreprises",
|
||||
form=form,
|
||||
entreprises_import=entreprises_import,
|
||||
)
|
||||
@ -964,7 +967,7 @@ def import_entreprises():
|
||||
|
||||
return render_template(
|
||||
"entreprises/import_entreprises.html",
|
||||
title=("Importation entreprises"),
|
||||
title="Importation entreprises",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -1028,10 +1031,12 @@ def verif_contact_data(contact_data):
|
||||
if contact_data[0] == "" or contact_data[1] == "" or contact_data[6] == "":
|
||||
return False
|
||||
|
||||
# entreprise_id existant
|
||||
entreprise = Entreprise.query.filter_by(id=contact_data[6]).first()
|
||||
if entreprise is None:
|
||||
return False
|
||||
|
||||
# contact possède le meme nom et prénom dans la meme entreprise
|
||||
contact = EntrepriseContact.query.filter_by(
|
||||
nom=contact_data[0], prenom=contact_data[1], entreprise_id=contact_data[6]
|
||||
).first()
|
||||
@ -1053,10 +1058,10 @@ def import_contacts():
|
||||
"""
|
||||
form = ImportForm()
|
||||
if form.validate_on_submit():
|
||||
path = os.path.join(Config.SCODOC_VAR_DIR, "tmp")
|
||||
file = form.fichier.data
|
||||
filename = secure_filename(file.filename)
|
||||
file_path = os.path.join(path, filename)
|
||||
file_path = os.path.join(
|
||||
Config.SCODOC_VAR_DIR, "tmp", secure_filename(file.filename)
|
||||
)
|
||||
file.save(file_path)
|
||||
data = sco_excel.excel_file_to_list(file_path)
|
||||
os.remove(file_path)
|
||||
@ -1076,7 +1081,7 @@ def import_contacts():
|
||||
flash("Veuillez utilisez la feuille excel à remplir")
|
||||
return render_template(
|
||||
"entreprises/import_contacts.html",
|
||||
title=("Importation contacts"),
|
||||
title="Importation contacts",
|
||||
form=form,
|
||||
)
|
||||
for contact_data in data[1][1:]:
|
||||
@ -1101,7 +1106,7 @@ def import_contacts():
|
||||
flash(f"Erreur lors de l'importation (ligne {ligne})")
|
||||
return render_template(
|
||||
"entreprises/import_contacts.html",
|
||||
title=("Importation contacts"),
|
||||
title="Importation contacts",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -1112,7 +1117,7 @@ def import_contacts():
|
||||
flash(f"Importation réussie de {len(contacts_import)} contact(s)")
|
||||
return render_template(
|
||||
"entreprises/import_contacts.html",
|
||||
title=("Importation Contacts"),
|
||||
title="Importation Contacts",
|
||||
form=form,
|
||||
contacts_import=contacts_import,
|
||||
)
|
||||
@ -1120,7 +1125,7 @@ def import_contacts():
|
||||
flash('Feuille "Contacts" vide')
|
||||
return render_template(
|
||||
"entreprises/import_contacts.html",
|
||||
title=("Importation contacts"),
|
||||
title="Importation contacts",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -1183,7 +1188,7 @@ def add_offre_file(offre_id):
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id))
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
title=("Ajout fichier à une offre"),
|
||||
title="Ajout fichier à une offre",
|
||||
form=form,
|
||||
)
|
||||
|
||||
@ -1212,6 +1217,6 @@ def delete_offre_file(offre_id, filedir):
|
||||
)
|
||||
return render_template(
|
||||
"entreprises/delete_confirmation.html",
|
||||
title=("Suppression fichier d'une offre"),
|
||||
title="Suppression fichier d'une offre",
|
||||
form=form,
|
||||
)
|
||||
|
@ -51,5 +51,12 @@
|
||||
document.getElementById("pays").value = ''
|
||||
}
|
||||
}
|
||||
|
||||
{# ajout margin-bottom sur le champ pays #}
|
||||
var champ_pays = document.getElementById("pays")
|
||||
if (champ_pays !== null) {
|
||||
var closest_form_group = champ_pays.closest(".form-group")
|
||||
closest_form_group.style.marginBottom = "50px"
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
@ -16,9 +16,11 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
<!-- pour le formulaire ajout offre -->
|
||||
var element = document.getElementById("depts");
|
||||
var closest_form_control = element.closest(".form-control")
|
||||
{# pour les formulaires offre #}
|
||||
var champ_depts = document.getElementById("depts")
|
||||
if (champ_depts !== null) {
|
||||
var closest_form_control = champ_depts.closest(".form-control")
|
||||
closest_form_control.classList.remove("form-control")
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user