2022-01-01 19:39:40 +01:00
|
|
|
<<<<<<< HEAD
|
|
|
|
=======
|
2022-01-01 18:02:23 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
|
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import re
|
|
|
|
import requests
|
|
|
|
|
2022-01-01 19:39:40 +01:00
|
|
|
>>>>>>> e0be0f8feef8cfb7f5da4fe516b33529ec1712c9
|
2021-12-27 11:48:58 +01:00
|
|
|
from flask_wtf import FlaskForm
|
2022-01-01 18:02:23 +01:00
|
|
|
from flask_wtf.file import FileField, FileAllowed, FileRequired
|
2021-12-23 19:28:25 +01:00
|
|
|
from markupsafe import Markup
|
2022-01-01 18:02:23 +01:00
|
|
|
from sqlalchemy import text
|
2021-12-27 19:00:38 +01:00
|
|
|
from wtforms import StringField, SubmitField, TextAreaField, SelectField, HiddenField
|
2022-01-01 18:02:23 +01:00
|
|
|
from wtforms.fields import EmailField, DateField
|
2021-12-23 19:28:25 +01:00
|
|
|
from wtforms.validators import ValidationError, DataRequired, Email
|
2022-01-01 18:02:23 +01:00
|
|
|
|
2021-12-24 12:12:41 +01:00
|
|
|
from app.entreprises.models import Entreprise, EntrepriseContact
|
2021-12-23 19:28:25 +01:00
|
|
|
from app.models import Identite
|
|
|
|
from app.auth.models import User
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
CHAMP_REQUIS = "Ce champ est requis"
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
|
|
|
class EntrepriseCreationForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
siret = StringField(
|
|
|
|
"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_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=[DataRequired(message=CHAMP_REQUIS)],
|
|
|
|
)
|
|
|
|
mail = EmailField(
|
|
|
|
"Mail du contact",
|
|
|
|
validators=[
|
|
|
|
DataRequired(message=CHAMP_REQUIS),
|
|
|
|
Email(message="Adresse e-mail invalide"),
|
|
|
|
],
|
|
|
|
)
|
2021-12-27 11:48:58 +01:00
|
|
|
poste = StringField("Poste du contact", validators=[])
|
|
|
|
service = StringField("Service du contact", validators=[])
|
|
|
|
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
|
|
|
def validate_siret(self, siret):
|
|
|
|
siret = siret.data.strip()
|
|
|
|
if re.match("^\d{14}$", siret) == None:
|
|
|
|
raise ValidationError("Format incorrect")
|
2021-12-28 21:20:50 +01:00
|
|
|
req = requests.get(
|
|
|
|
f"https://entreprise.data.gouv.fr/api/sirene/v1/siret/{siret}"
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if req.status_code != 200:
|
|
|
|
raise ValidationError("SIRET inexistant")
|
|
|
|
entreprise = Entreprise.query.filter_by(siret=siret).first()
|
|
|
|
if entreprise is not None:
|
2021-12-28 21:20:50 +01:00
|
|
|
lien = f'<a href="/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}">ici</a>'
|
|
|
|
raise ValidationError(
|
|
|
|
Markup(f"Entreprise déjà présent, lien vers la fiche : {lien}")
|
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
|
|
|
class EntrepriseModificationForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
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)])
|
2021-12-27 11:48:58 +01:00
|
|
|
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class OffreCreationForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
intitule = StringField("Intitulé", validators=[DataRequired(message=CHAMP_REQUIS)])
|
|
|
|
description = TextAreaField(
|
|
|
|
"Description", validators=[DataRequired(message=CHAMP_REQUIS)]
|
|
|
|
)
|
|
|
|
type_offre = SelectField(
|
|
|
|
"Type de l'offre",
|
|
|
|
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)])
|
2021-12-27 11:48:58 +01:00
|
|
|
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class OffreModificationForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
intitule = StringField("Intitulé", validators=[DataRequired(message=CHAMP_REQUIS)])
|
|
|
|
description = TextAreaField(
|
|
|
|
"Description", validators=[DataRequired(message=CHAMP_REQUIS)]
|
|
|
|
)
|
|
|
|
type_offre = SelectField(
|
|
|
|
"Type de l'offre",
|
|
|
|
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)])
|
2021-12-27 11:48:58 +01:00
|
|
|
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class ContactCreationForm(FlaskForm):
|
2021-12-24 16:07:36 +01:00
|
|
|
hidden_entreprise_id = HiddenField()
|
2021-12-28 21:20:50 +01:00
|
|
|
nom = StringField("Nom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
|
|
|
prenom = StringField("Prénom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
|
|
|
telephone = StringField(
|
|
|
|
"Téléphone", validators=[DataRequired(message=CHAMP_REQUIS)]
|
|
|
|
)
|
|
|
|
mail = EmailField(
|
|
|
|
"Mail",
|
|
|
|
validators=[
|
|
|
|
DataRequired(message=CHAMP_REQUIS),
|
|
|
|
Email(message="Adresse e-mail invalide"),
|
|
|
|
],
|
|
|
|
)
|
2021-12-24 16:07:36 +01:00
|
|
|
poste = StringField("Poste", validators=[])
|
|
|
|
service = StringField("Service", validators=[])
|
2021-12-27 11:48:58 +01:00
|
|
|
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-24 12:12:41 +01:00
|
|
|
def validate(self):
|
|
|
|
rv = FlaskForm.validate(self)
|
|
|
|
if not rv:
|
|
|
|
return False
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-24 12:12:41 +01:00
|
|
|
contact = EntrepriseContact.query.filter_by(
|
2021-12-28 21:20:50 +01:00
|
|
|
entreprise_id=self.hidden_entreprise_id.data,
|
|
|
|
nom=self.nom.data,
|
|
|
|
prenom=self.prenom.data,
|
2021-12-24 12:12:41 +01:00
|
|
|
).first()
|
|
|
|
|
|
|
|
if contact is not None:
|
|
|
|
self.nom.errors.append("Ce contact existe déjà (même nom et prénom)")
|
|
|
|
self.prenom.errors.append("")
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class ContactModificationForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
nom = StringField("Nom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
|
|
|
prenom = StringField("Prénom", validators=[DataRequired(message=CHAMP_REQUIS)])
|
|
|
|
telephone = StringField(
|
|
|
|
"Téléphone", validators=[DataRequired(message=CHAMP_REQUIS)]
|
|
|
|
)
|
|
|
|
mail = EmailField(
|
|
|
|
"Mail",
|
|
|
|
validators=[
|
|
|
|
DataRequired(message=CHAMP_REQUIS),
|
|
|
|
Email(message="Adresse e-mail invalide"),
|
|
|
|
],
|
|
|
|
)
|
2021-12-27 11:48:58 +01:00
|
|
|
poste = StringField("Poste", validators=[])
|
|
|
|
service = StringField("Service", validators=[])
|
|
|
|
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class HistoriqueCreationForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
etudiant = StringField(
|
|
|
|
"Étudiant",
|
|
|
|
validators=[DataRequired(message=CHAMP_REQUIS)],
|
|
|
|
render_kw={"placeholder": "Tapez le nom de l'étudiant puis selectionnez"},
|
|
|
|
)
|
|
|
|
type_offre = SelectField(
|
|
|
|
"Type de l'offre",
|
|
|
|
choices=[("Stage"), ("Alternance")],
|
|
|
|
validators=[DataRequired(message=CHAMP_REQUIS)],
|
|
|
|
)
|
|
|
|
date_debut = DateField(
|
|
|
|
"Date début", validators=[DataRequired(message=CHAMP_REQUIS)]
|
|
|
|
)
|
|
|
|
date_fin = DateField("Date fin", validators=[DataRequired(message=CHAMP_REQUIS)])
|
2021-12-27 11:48:58 +01:00
|
|
|
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
|
|
|
def validate(self):
|
|
|
|
rv = FlaskForm.validate(self)
|
|
|
|
if not rv:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if 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
|
|
|
|
|
|
|
|
def validate_etudiant(self, etudiant):
|
|
|
|
etudiant_data = etudiant.data.upper().strip()
|
2021-12-28 21:20:50 +01:00
|
|
|
stm = text(
|
|
|
|
"SELECT id, CONCAT(nom, ' ', prenom) as nom_prenom FROM Identite WHERE CONCAT(nom, ' ', prenom)=:nom_prenom"
|
|
|
|
)
|
|
|
|
etudiant = (
|
|
|
|
Identite.query.from_statement(stm).params(nom_prenom=etudiant_data).first()
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if etudiant is None:
|
|
|
|
raise ValidationError("Champ incorrect (selectionnez dans la liste)")
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class EnvoiOffreForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
responsable = StringField(
|
|
|
|
"Responsable de formation",
|
|
|
|
validators=[DataRequired(message=CHAMP_REQUIS)],
|
|
|
|
)
|
2021-12-27 11:48:58 +01:00
|
|
|
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
2021-12-23 19:28:25 +01:00
|
|
|
|
|
|
|
def validate_responsable(self, responsable):
|
|
|
|
responsable_data = responsable.data.upper().strip()
|
2021-12-28 21:20:50 +01:00
|
|
|
stm = text(
|
|
|
|
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:responsable_data"
|
|
|
|
)
|
|
|
|
responsable = (
|
|
|
|
User.query.from_statement(stm)
|
|
|
|
.params(responsable_data=responsable_data)
|
|
|
|
.first()
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if responsable is None:
|
|
|
|
raise ValidationError("Champ incorrect (selectionnez dans la liste)")
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
|
|
|
class AjoutFichierForm(FlaskForm):
|
|
|
|
fichier = FileField(
|
|
|
|
"Fichier",
|
|
|
|
validators=[
|
|
|
|
FileRequired(message=CHAMP_REQUIS),
|
|
|
|
FileAllowed(["pdf", "docx"], "Fichier .pdf ou .docx uniquement"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
|
|
|
|
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class SuppressionConfirmationForm(FlaskForm):
|
2021-12-28 21:20:50 +01:00
|
|
|
submit = SubmitField("Supprimer", render_kw={"style": "margin-bottom: 10px;"})
|