2021-12-27 19:00:38 +01:00
|
|
|
import os
|
|
|
|
from config import Config
|
2022-01-24 18:07:54 +01:00
|
|
|
from datetime import datetime, date
|
2021-12-28 21:20:50 +01:00
|
|
|
import glob
|
|
|
|
import shutil
|
2021-12-27 19:00:38 +01:00
|
|
|
|
2021-12-27 11:48:58 +01:00
|
|
|
from flask import render_template, redirect, url_for, request, flash, send_file, abort
|
2021-12-23 19:28:25 +01:00
|
|
|
from flask.json import jsonify
|
|
|
|
from flask_login import current_user
|
2021-12-27 11:48:58 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
from app.decorators import permission_required
|
2021-12-24 18:10:19 +01:00
|
|
|
|
|
|
|
from app.entreprises import LOGS_LEN
|
2021-12-23 19:28:25 +01:00
|
|
|
from app.entreprises.forms import (
|
2022-04-07 02:54:11 +02:00
|
|
|
CorrespondantsCreationForm,
|
2022-04-21 21:18:47 +02:00
|
|
|
DesactivationConfirmationForm,
|
2021-12-23 19:28:25 +01:00
|
|
|
EntrepriseCreationForm,
|
|
|
|
EntrepriseModificationForm,
|
2022-04-25 20:49:21 +02:00
|
|
|
SiteCreationForm,
|
2021-12-23 19:28:25 +01:00
|
|
|
SuppressionConfirmationForm,
|
|
|
|
OffreCreationForm,
|
|
|
|
OffreModificationForm,
|
2022-03-28 23:44:57 +02:00
|
|
|
CorrespondantModificationForm,
|
2022-04-05 02:26:43 +02:00
|
|
|
ContactCreationForm,
|
|
|
|
ContactModificationForm,
|
2022-03-28 23:44:57 +02:00
|
|
|
StageApprentissageCreationForm,
|
|
|
|
StageApprentissageModificationForm,
|
2021-12-28 21:20:50 +01:00
|
|
|
EnvoiOffreForm,
|
|
|
|
AjoutFichierForm,
|
2022-02-01 18:35:48 +01:00
|
|
|
ValidationConfirmationForm,
|
2022-02-10 21:17:22 +01:00
|
|
|
ImportForm,
|
2022-02-22 21:52:32 +01:00
|
|
|
PreferencesForm,
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
from app.entreprises import bp
|
|
|
|
from app.entreprises.models import (
|
|
|
|
Entreprise,
|
|
|
|
EntrepriseOffre,
|
2022-03-28 23:44:57 +02:00
|
|
|
EntrepriseCorrespondant,
|
2021-12-23 19:28:25 +01:00
|
|
|
EntrepriseLog,
|
2022-04-05 02:26:43 +02:00
|
|
|
EntrepriseContact,
|
2022-04-25 20:49:21 +02:00
|
|
|
EntrepriseSite,
|
2022-03-28 23:44:57 +02:00
|
|
|
EntrepriseStageApprentissage,
|
2021-12-28 21:20:50 +01:00
|
|
|
EntrepriseEnvoiOffre,
|
2022-02-03 18:07:16 +01:00
|
|
|
EntrepriseOffreDepartement,
|
2022-02-22 21:52:32 +01:00
|
|
|
EntreprisePreferences,
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-02-15 18:24:10 +01:00
|
|
|
from app.entreprises import app_relations_entreprises as are
|
2021-12-28 21:20:50 +01:00
|
|
|
from app.models import Identite
|
2021-12-23 19:28:25 +01:00
|
|
|
from app.auth.models import User
|
2021-12-27 11:48:58 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2021-12-24 18:10:19 +01:00
|
|
|
from app.scodoc import sco_etud, sco_excel
|
|
|
|
import app.scodoc.sco_utils as scu
|
2021-12-27 11:48:58 +01:00
|
|
|
|
|
|
|
from app import db
|
2021-12-23 19:28:25 +01:00
|
|
|
from sqlalchemy import text
|
2021-12-29 11:26:41 +01:00
|
|
|
from werkzeug.utils import secure_filename
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 23:21:47 +01:00
|
|
|
@bp.route("/", methods=["GET"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
2021-12-23 19:28:25 +01:00
|
|
|
def index():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet d'afficher une page avec la liste des entreprises (visible) et une liste des dernières opérations
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-04-20 22:37:04 +02:00
|
|
|
entreprises = Entreprise.query.filter_by(visible=True, active=True)
|
2021-12-23 19:28:25 +01:00
|
|
|
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/entreprises.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Entreprises",
|
2021-12-28 21:20:50 +01:00
|
|
|
entreprises=entreprises,
|
|
|
|
logs=logs,
|
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-01-31 18:22:54 +01:00
|
|
|
@bp.route("/logs", methods=["GET"])
|
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
|
|
|
def logs():
|
|
|
|
"""
|
|
|
|
Permet d'afficher les logs (toutes les entreprises)
|
|
|
|
"""
|
|
|
|
page = request.args.get("page", 1, type=int)
|
|
|
|
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).paginate(
|
|
|
|
page=page, per_page=20
|
|
|
|
)
|
2022-02-08 16:40:32 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/logs.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Logs",
|
2022-02-08 16:40:32 +01:00
|
|
|
logs=logs,
|
|
|
|
)
|
2022-01-31 18:22:54 +01:00
|
|
|
|
|
|
|
|
2022-01-25 19:42:17 +01:00
|
|
|
@bp.route("/validation", methods=["GET"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesValidate)
|
2022-02-02 19:13:50 +01:00
|
|
|
def validation():
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet d'afficher une page avec la liste des entreprises a valider (non visible)
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
2022-01-25 19:42:17 +01:00
|
|
|
entreprises = Entreprise.query.filter_by(visible=False).all()
|
|
|
|
return render_template(
|
2022-01-26 18:42:48 +01:00
|
|
|
"entreprises/entreprises_validation.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Validation entreprises",
|
2022-01-25 19:42:17 +01:00
|
|
|
entreprises=entreprises,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-03-28 23:44:57 +02:00
|
|
|
@bp.route("/correspondants", methods=["GET"])
|
2022-04-21 21:18:47 +02:00
|
|
|
@permission_required(Permission.RelationsEntreprisesCorrespondants)
|
2022-03-28 23:44:57 +02:00
|
|
|
def correspondants():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet d'afficher une page avec la liste des correspondants des entreprises visibles et une liste des dernières opérations
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants = (
|
|
|
|
db.session.query(EntrepriseCorrespondant, Entreprise)
|
|
|
|
.join(Entreprise, EntrepriseCorrespondant.entreprise_id == Entreprise.id)
|
2022-04-21 21:18:47 +02:00
|
|
|
.filter_by(visible=True, active=True)
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
2021-12-23 23:21:47 +01:00
|
|
|
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-03-28 23:44:57 +02:00
|
|
|
"entreprises/correspondants.html",
|
|
|
|
title="Correspondants",
|
|
|
|
correspondants=correspondants,
|
2022-02-08 16:40:32 +01:00
|
|
|
logs=logs,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 23:21:47 +01:00
|
|
|
|
2021-12-27 19:00:38 +01:00
|
|
|
@bp.route("/fiche_entreprise/<int:id>", methods=["GET"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
2021-12-23 23:21:47 +01:00
|
|
|
def fiche_entreprise(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'afficher la fiche entreprise d'une entreprise avec une liste des dernières opérations et
|
|
|
|
l'historique des étudiants ayant réaliser un stage ou une alternance dans cette entreprise.
|
2022-03-28 23:44:57 +02:00
|
|
|
La fiche entreprise comporte les informations de l'entreprise, les correspondants de l'entreprise et
|
2021-12-29 19:40:57 +01:00
|
|
|
les offres de l'entreprise.
|
|
|
|
"""
|
2022-04-21 21:18:47 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=id, visible=True, active=True
|
|
|
|
).first_or_404(description=f"fiche entreprise {id} inconnue")
|
2021-12-28 21:20:50 +01:00
|
|
|
offres_with_files = []
|
2022-02-15 18:24:10 +01:00
|
|
|
depts = are.get_depts()
|
2022-02-10 21:17:22 +01:00
|
|
|
for offre in entreprise.offres:
|
2022-03-01 18:45:04 +01:00
|
|
|
if not offre.expired and (
|
|
|
|
offre.expiration_date is None
|
|
|
|
or (
|
|
|
|
offre.expiration_date is not None
|
|
|
|
and date.today() < offre.expiration_date
|
|
|
|
)
|
|
|
|
):
|
2022-02-15 18:24:10 +01:00
|
|
|
offre_with_files = are.get_offre_files_and_depts(offre, depts)
|
|
|
|
if offre_with_files is not None:
|
|
|
|
offres_with_files.append(offre_with_files)
|
2022-04-25 20:49:21 +02:00
|
|
|
sites = entreprise.sites[:]
|
2021-12-28 21:20:50 +01:00
|
|
|
logs = (
|
|
|
|
EntrepriseLog.query.order_by(EntrepriseLog.date.desc())
|
|
|
|
.filter_by(object=id)
|
|
|
|
.limit(LOGS_LEN)
|
|
|
|
.all()
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
stages_apprentissages = (
|
|
|
|
db.session.query(EntrepriseStageApprentissage, Identite)
|
|
|
|
.order_by(EntrepriseStageApprentissage.date_debut.desc())
|
|
|
|
.filter(EntrepriseStageApprentissage.entreprise_id == id)
|
|
|
|
.join(Identite, Identite.id == EntrepriseStageApprentissage.etudid)
|
2021-12-28 21:20:50 +01:00
|
|
|
.all()
|
|
|
|
)
|
|
|
|
return render_template(
|
|
|
|
"entreprises/fiche_entreprise.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Fiche entreprise",
|
2021-12-28 21:20:50 +01:00
|
|
|
entreprise=entreprise,
|
2022-04-25 20:49:21 +02:00
|
|
|
sites=sites,
|
2021-12-28 21:20:50 +01:00
|
|
|
offres=offres_with_files,
|
|
|
|
logs=logs,
|
2022-03-28 23:44:57 +02:00
|
|
|
stages_apprentissages=stages_apprentissages,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 23:21:47 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:id>/logs", methods=["GET"])
|
2022-02-02 19:13:50 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
|
|
|
def logs_entreprise(id):
|
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet d'afficher les logs d'une entreprise
|
2022-02-02 19:13:50 +01:00
|
|
|
"""
|
|
|
|
page = request.args.get("page", 1, type=int)
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
|
|
|
description=f"logs fiche entreprise {id} inconnu"
|
|
|
|
)
|
2022-02-02 19:13:50 +01:00
|
|
|
logs = (
|
|
|
|
EntrepriseLog.query.order_by(EntrepriseLog.date.desc())
|
|
|
|
.filter_by(object=id)
|
|
|
|
.paginate(page=page, per_page=20)
|
|
|
|
)
|
|
|
|
return render_template(
|
|
|
|
"entreprises/logs_entreprise.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Logs",
|
2022-02-02 19:13:50 +01:00
|
|
|
logs=logs,
|
|
|
|
entreprise=entreprise,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-26 18:42:48 +01:00
|
|
|
@bp.route("/fiche_entreprise_validation/<int:id>", methods=["GET"])
|
|
|
|
@permission_required(Permission.RelationsEntreprisesValidate)
|
|
|
|
def fiche_entreprise_validation(id):
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
|
|
|
Permet d'afficher la fiche entreprise d'une entreprise a valider
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=False).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"fiche entreprise (validation) {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants = entreprise.correspondants
|
2022-01-26 18:42:48 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/fiche_entreprise_validation.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Validation fiche entreprise",
|
2022-01-26 18:42:48 +01:00
|
|
|
entreprise=entreprise,
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants=correspondants,
|
2022-01-26 18:42:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-25 19:42:17 +01:00
|
|
|
@bp.route("/offres_recues", methods=["GET"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
2022-01-27 16:28:28 +01:00
|
|
|
def offres_recues():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet d'afficher la page où l'on peut voir les offres reçues
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
offres_recues = (
|
2021-12-28 21:20:50 +01:00
|
|
|
db.session.query(EntrepriseEnvoiOffre, EntrepriseOffre)
|
|
|
|
.filter(EntrepriseEnvoiOffre.receiver_id == current_user.id)
|
|
|
|
.join(EntrepriseOffre, EntrepriseOffre.id == EntrepriseEnvoiOffre.offre_id)
|
|
|
|
.all()
|
|
|
|
)
|
2022-02-01 18:35:48 +01:00
|
|
|
offres_recues_with_files = []
|
|
|
|
for offre in offres_recues:
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant = EntrepriseCorrespondant.query.filter_by(
|
|
|
|
id=offre[1].correspondant_id
|
|
|
|
).first()
|
2022-02-01 18:35:48 +01:00
|
|
|
files = []
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{offre[1].entreprise_id}",
|
|
|
|
f"{offre[1].id}",
|
|
|
|
)
|
|
|
|
if os.path.exists(path):
|
|
|
|
for dir in glob.glob(
|
|
|
|
f"{path}/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"
|
|
|
|
):
|
|
|
|
for file in glob.glob(f"{dir}/*"):
|
|
|
|
file = [os.path.basename(dir), os.path.basename(file)]
|
|
|
|
files.append(file)
|
2022-03-28 23:44:57 +02:00
|
|
|
offres_recues_with_files.append([offre[0], offre[1], files, correspondant])
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-01-25 19:42:17 +01:00
|
|
|
"entreprises/offres_recues.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Offres reçues",
|
2022-02-01 18:35:48 +01:00
|
|
|
offres_recues=offres_recues_with_files,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-24 16:07:36 +01:00
|
|
|
|
2022-01-24 19:02:16 +01:00
|
|
|
@bp.route("/fiche_entreprise/<int:id>/offres_expirees")
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
2022-01-24 19:02:16 +01:00
|
|
|
def offres_expirees(id):
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
|
|
|
Permet d'afficher la liste des offres expirés d'une entreprise
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"fiche entreprise {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-01-24 19:02:16 +01:00
|
|
|
offres_expirees_with_files = []
|
2022-02-15 18:24:10 +01:00
|
|
|
depts = are.get_depts()
|
|
|
|
for offre in entreprise.offres:
|
2022-03-01 18:45:04 +01:00
|
|
|
if offre.expired or (
|
|
|
|
offre.expiration_date is not None and date.today() > offre.expiration_date
|
|
|
|
):
|
2022-02-15 18:24:10 +01:00
|
|
|
offre_expiree_with_files = are.get_offre_files_and_depts(offre, depts)
|
|
|
|
if offre_expiree_with_files is not None:
|
|
|
|
offres_expirees_with_files.append(offre_expiree_with_files)
|
2022-01-24 19:02:16 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/offres_expirees.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Offres expirées",
|
2022-01-24 19:02:16 +01:00
|
|
|
entreprise=entreprise,
|
|
|
|
offres_expirees=offres_expirees_with_files,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
@bp.route("/add_entreprise", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-23 19:28:25 +01:00
|
|
|
def add_entreprise():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'ajouter une entreprise dans la base avec un formulaire
|
|
|
|
"""
|
2021-12-23 19:28:25 +01:00
|
|
|
form = EntrepriseCreationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
entreprise = Entreprise(
|
|
|
|
nom=form.nom_entreprise.data.strip(),
|
|
|
|
siret=form.siret.data.strip(),
|
|
|
|
adresse=form.adresse.data.strip(),
|
|
|
|
codepostal=form.codepostal.data.strip(),
|
|
|
|
ville=form.ville.data.strip(),
|
2022-02-28 18:57:05 +01:00
|
|
|
pays=form.pays.data.strip() if form.pays.data.strip() else "FRANCE",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(entreprise)
|
|
|
|
db.session.commit()
|
2022-04-25 20:49:21 +02:00
|
|
|
db.session.refresh(entreprise)
|
|
|
|
site = EntrepriseSite(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
nom=form.nom_entreprise.data.strip(),
|
|
|
|
adresse=form.adresse.data.strip(),
|
|
|
|
codepostal=form.codepostal.data.strip(),
|
|
|
|
ville=form.ville.data.strip(),
|
|
|
|
pays=form.pays.data.strip() if form.pays.data.strip() else "FRANCE",
|
|
|
|
)
|
|
|
|
db.session.add(site)
|
|
|
|
db.session.commit()
|
2022-04-13 20:59:26 +02:00
|
|
|
if form.nom_correspondant.data.strip():
|
2022-04-25 20:49:21 +02:00
|
|
|
db.session.refresh(site)
|
2022-04-13 20:59:26 +02:00
|
|
|
correspondant = EntrepriseCorrespondant(
|
|
|
|
entreprise_id=entreprise.id,
|
2022-04-25 20:49:21 +02:00
|
|
|
site_id=site.id,
|
2022-04-20 22:37:04 +02:00
|
|
|
civilite=form.civilite.data,
|
2022-04-13 20:59:26 +02:00
|
|
|
nom=form.nom_correspondant.data.strip(),
|
|
|
|
prenom=form.prenom_correspondant.data.strip(),
|
|
|
|
telephone=form.telephone.data.strip(),
|
|
|
|
mail=form.mail.data.strip(),
|
|
|
|
poste=form.poste.data.strip(),
|
|
|
|
service=form.service.data.strip(),
|
2022-04-20 22:37:04 +02:00
|
|
|
origine=form.origine.data.strip(),
|
|
|
|
notes=form.notes.data.strip(),
|
2022-04-13 20:59:26 +02:00
|
|
|
)
|
|
|
|
db.session.add(correspondant)
|
2022-02-02 19:13:50 +01:00
|
|
|
if current_user.has_permission(Permission.RelationsEntreprisesValidate, None):
|
|
|
|
entreprise.visible = True
|
|
|
|
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom}</a>"
|
|
|
|
log = EntrepriseLog(
|
|
|
|
authenticated_user=current_user.user_name,
|
2022-04-12 00:21:25 +02:00
|
|
|
text=f"{nom_entreprise} - Création de la fiche entreprise ({entreprise.nom})",
|
2022-02-02 19:13:50 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été ajouté à la liste.")
|
|
|
|
return redirect(url_for("entreprises.index"))
|
|
|
|
else:
|
|
|
|
entreprise.visible = False
|
|
|
|
db.session.commit()
|
2022-02-23 19:12:26 +01:00
|
|
|
if EntreprisePreferences.get_email_notifications():
|
|
|
|
are.send_email_notifications_entreprise(
|
2022-04-12 00:21:25 +02:00
|
|
|
"entreprise en attente de validation", entreprise
|
2022-02-23 19:12:26 +01:00
|
|
|
)
|
2022-02-02 19:13:50 +01:00
|
|
|
flash("L'entreprise a été ajouté à la liste pour la validation.")
|
|
|
|
return redirect(url_for("entreprises.index"))
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/ajout_entreprise.html",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Ajout entreprise avec correspondant",
|
2021-12-28 21:20:50 +01:00
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/edit_entreprise/<int:id>", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-23 19:28:25 +01:00
|
|
|
def edit_entreprise(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de modifier une entreprise de la base avec un formulaire
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"entreprise {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-02-28 18:57:05 +01:00
|
|
|
form = EntrepriseModificationForm(hidden_entreprise_siret=entreprise.siret)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{form.nom.data.strip()}</a>"
|
|
|
|
if entreprise.nom != form.nom.data.strip():
|
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=entreprise.id,
|
2022-02-28 18:57:05 +01:00
|
|
|
text=f"{nom_entreprise} - Modification du nom (ancien nom: {entreprise.nom})",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.nom = form.nom.data.strip()
|
|
|
|
db.session.add(log)
|
|
|
|
if entreprise.adresse != form.adresse.data.strip():
|
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=entreprise.id,
|
2022-02-28 18:57:05 +01:00
|
|
|
text=f"{nom_entreprise} - Modification de l'adresse (ancienne adresse: {entreprise.adresse})",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.adresse = form.adresse.data.strip()
|
|
|
|
db.session.add(log)
|
|
|
|
if entreprise.codepostal != form.codepostal.data.strip():
|
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=entreprise.id,
|
2022-02-28 18:57:05 +01:00
|
|
|
text=f"{nom_entreprise} - Modification du code postal (ancien code postal: {entreprise.codepostal})",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.codepostal = form.codepostal.data.strip()
|
|
|
|
db.session.add(log)
|
|
|
|
if entreprise.ville != form.ville.data.strip():
|
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=entreprise.id,
|
2022-02-28 18:57:05 +01:00
|
|
|
text=f"{nom_entreprise} - Modification de la ville (ancienne ville: {entreprise.ville})",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.ville = form.ville.data.strip()
|
|
|
|
db.session.add(log)
|
2022-02-28 18:57:05 +01:00
|
|
|
if entreprise.pays != form.pays.data.strip() or not form.pays.data.strip():
|
2021-12-23 19:28:25 +01:00
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=entreprise.id,
|
2022-02-28 18:57:05 +01:00
|
|
|
text=f"{nom_entreprise} - Modification du pays (ancien pays: {entreprise.pays})",
|
|
|
|
)
|
|
|
|
entreprise.pays = (
|
|
|
|
form.pays.data.strip() if form.pays.data.strip() else "FRANCE"
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été modifié.")
|
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
2021-12-28 21:20:50 +01:00
|
|
|
elif request.method == "GET":
|
2021-12-23 19:28:25 +01:00
|
|
|
form.siret.data = entreprise.siret
|
|
|
|
form.nom.data = entreprise.nom
|
|
|
|
form.adresse.data = entreprise.adresse
|
|
|
|
form.codepostal.data = entreprise.codepostal
|
|
|
|
form.ville.data = entreprise.ville
|
|
|
|
form.pays.data = entreprise.pays
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-02-18 19:57:19 +01:00
|
|
|
"entreprises/form_modification_entreprise.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Modification entreprise",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-04-20 22:37:04 +02:00
|
|
|
@bp.route("/fiche_entreprise/desactiver/<int:id>", methods=["GET", "POST"])
|
2022-04-21 21:18:47 +02:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2022-04-20 22:37:04 +02:00
|
|
|
def fiche_entreprise_desactiver(id):
|
2022-04-21 21:18:47 +02:00
|
|
|
"""
|
|
|
|
Permet de désactiver une entreprise
|
|
|
|
"""
|
2022-04-20 22:37:04 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
|
|
|
description=f"entreprise {id} inconnue"
|
|
|
|
)
|
2022-04-21 21:18:47 +02:00
|
|
|
form = DesactivationConfirmationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
entreprise.notes_active = form.notes_active.data.strip()
|
|
|
|
entreprise.active = False
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été désactivé.")
|
|
|
|
return redirect(url_for("entreprises.index"))
|
|
|
|
return render_template(
|
|
|
|
"entreprises/confirmation_form.html",
|
|
|
|
title="Désactiver entreprise",
|
|
|
|
form=form,
|
|
|
|
info_message="Cliquez sur le bouton Désactiver pour confirmer la désactivation",
|
|
|
|
)
|
2022-04-20 22:37:04 +02:00
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise_validation/<int:id>/validate_entreprise", methods=["GET", "POST"]
|
|
|
|
)
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesValidate)
|
|
|
|
def validate_entreprise(id):
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
|
|
|
Permet de valider une entreprise
|
|
|
|
"""
|
2022-02-01 18:35:48 +01:00
|
|
|
form = ValidationConfirmationForm()
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=False).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"entreprise (validation) {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-02-01 18:35:48 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
entreprise.visible = True
|
2022-02-02 19:13:50 +01:00
|
|
|
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom}</a>"
|
|
|
|
log = EntrepriseLog(
|
|
|
|
authenticated_user=current_user.user_name,
|
2022-03-28 23:44:57 +02:00
|
|
|
text=f"{nom_entreprise} - Validation de la fiche entreprise ({entreprise.nom}) avec un correspondant",
|
2022-02-02 19:13:50 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-02-01 18:35:48 +01:00
|
|
|
db.session.commit()
|
2022-02-02 19:13:50 +01:00
|
|
|
flash("L'entreprise a été validé et ajouté à la liste.")
|
|
|
|
return redirect(url_for("entreprises.index"))
|
2022-02-01 18:35:48 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/validate_confirmation.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Validation entreprise",
|
2022-02-01 18:35:48 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2022-01-26 18:42:48 +01:00
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise_validation/<int:id>/delete_validation_entreprise",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2022-02-14 19:42:17 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesValidate)
|
|
|
|
def delete_validation_entreprise(id):
|
|
|
|
"""
|
|
|
|
Permet de supprimer une entreprise en attente de validation avec une formulaire de validation
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=False).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"entreprise (validation) {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-02-14 19:42:17 +01:00
|
|
|
form = SuppressionConfirmationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(entreprise)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été supprimé de la liste des entreprise à valider.")
|
|
|
|
return redirect(url_for("entreprises.validation"))
|
|
|
|
return render_template(
|
2022-04-21 21:18:47 +02:00
|
|
|
"entreprises/confirmation_form.html",
|
2022-02-14 19:42:17 +01:00
|
|
|
title="Supression entreprise",
|
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2022-02-14 19:42:17 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:id>/add_offre", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-23 19:28:25 +01:00
|
|
|
def add_offre(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'ajouter une offre a une entreprise
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"entreprise {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-03-04 17:10:07 +01:00
|
|
|
form = OffreCreationForm(hidden_entreprise_id=id)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
offre = EntrepriseOffre(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
intitule=form.intitule.data.strip(),
|
|
|
|
description=form.description.data.strip(),
|
|
|
|
type_offre=form.type_offre.data.strip(),
|
|
|
|
missions=form.missions.data.strip(),
|
2021-12-28 21:20:50 +01:00
|
|
|
duree=form.duree.data.strip(),
|
2022-01-24 18:07:54 +01:00
|
|
|
expiration_date=form.expiration_date.data,
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant_id=form.correspondant.data,
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-02-03 18:07:16 +01:00
|
|
|
db.session.add(offre)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(offre)
|
|
|
|
for dept in form.depts.data:
|
|
|
|
offre_dept = EntrepriseOffreDepartement(
|
|
|
|
offre_id=offre.id,
|
|
|
|
dept_id=dept,
|
|
|
|
)
|
|
|
|
db.session.add(offre_dept)
|
2022-04-12 19:44:09 +02:00
|
|
|
if form.fichier.data:
|
|
|
|
date = f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}"
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{offre.entreprise_id}",
|
|
|
|
f"{offre.id}",
|
|
|
|
f"{date}",
|
|
|
|
)
|
|
|
|
os.makedirs(path)
|
|
|
|
file = form.fichier.data
|
|
|
|
filename = secure_filename(file.filename)
|
|
|
|
file.save(os.path.join(path, filename))
|
2021-12-23 19:28:25 +01:00
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=entreprise.id,
|
|
|
|
text="Création d'une offre",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'offre a été ajouté à la fiche entreprise.")
|
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
2022-02-08 16:40:32 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/form.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Ajout offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/edit_offre/<int:id>", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-23 19:28:25 +01:00
|
|
|
def edit_offre(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de modifier une offre
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
offre = EntrepriseOffre.query.filter_by(id=id).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"offre {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-02-04 17:12:56 +01:00
|
|
|
offre_depts = EntrepriseOffreDepartement.query.filter_by(offre_id=offre.id).all()
|
2022-03-04 17:10:07 +01:00
|
|
|
form = OffreModificationForm(
|
2022-03-28 23:44:57 +02:00
|
|
|
hidden_entreprise_id=offre.entreprise_id, correspondant=offre.correspondant_id
|
2022-03-04 17:10:07 +01:00
|
|
|
)
|
2022-02-04 17:12:56 +01:00
|
|
|
offre_depts_list = [(offre_dept.dept_id) for offre_dept in offre_depts]
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
offre.intitule = form.intitule.data.strip()
|
|
|
|
offre.description = form.description.data.strip()
|
|
|
|
offre.type_offre = form.type_offre.data.strip()
|
|
|
|
offre.missions = form.missions.data.strip()
|
|
|
|
offre.duree = form.duree.data.strip()
|
2022-01-24 18:07:54 +01:00
|
|
|
offre.expiration_date = form.expiration_date.data
|
2022-03-28 23:44:57 +02:00
|
|
|
offre.correspondant_id = form.correspondant.data
|
2022-02-04 17:12:56 +01:00
|
|
|
if offre_depts_list != form.depts.data:
|
|
|
|
for dept in form.depts.data:
|
|
|
|
if dept not in offre_depts_list:
|
|
|
|
offre_dept = EntrepriseOffreDepartement(
|
|
|
|
offre_id=offre.id,
|
|
|
|
dept_id=dept,
|
|
|
|
)
|
|
|
|
db.session.add(offre_dept)
|
|
|
|
for dept in offre_depts_list:
|
|
|
|
if dept not in form.depts.data:
|
|
|
|
offre_dept = EntrepriseOffreDepartement.query.filter_by(
|
|
|
|
offre_id=offre.id, dept_id=dept
|
|
|
|
).first_or_404()
|
|
|
|
db.session.delete(offre_dept)
|
2021-12-23 19:28:25 +01:00
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=offre.entreprise_id,
|
|
|
|
text="Modification d'une offre",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'offre a été modifié.")
|
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise.id))
|
2021-12-28 21:20:50 +01:00
|
|
|
elif request.method == "GET":
|
2021-12-23 19:28:25 +01:00
|
|
|
form.intitule.data = offre.intitule
|
|
|
|
form.description.data = offre.description
|
|
|
|
form.type_offre.data = offre.type_offre
|
|
|
|
form.missions.data = offre.missions
|
|
|
|
form.duree.data = offre.duree
|
2022-01-24 18:07:54 +01:00
|
|
|
form.expiration_date.data = offre.expiration_date
|
2022-02-04 17:12:56 +01:00
|
|
|
form.depts.data = offre_depts_list
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-02-08 16:40:32 +01:00
|
|
|
"entreprises/form.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Modification offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/delete_offre/<int:id>", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-23 19:28:25 +01:00
|
|
|
def delete_offre(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de supprimer une offre
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
offre = EntrepriseOffre.query.filter_by(id=id).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"offre {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
entreprise_id = offre.entreprise.id
|
|
|
|
form = SuppressionConfirmationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(offre)
|
2022-02-08 16:40:32 +01:00
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{entreprise_id}",
|
|
|
|
f"{offre.id}",
|
|
|
|
)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
2021-12-23 19:28:25 +01:00
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=offre.entreprise_id,
|
|
|
|
text="Suppression d'une offre",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'offre a été supprimé de la fiche entreprise.")
|
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id))
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-04-21 21:18:47 +02:00
|
|
|
"entreprises/confirmation_form.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Supression offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/offres_recues/delete_offre_recue/<int:id>", methods=["GET", "POST"])
|
2022-02-14 19:42:17 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
|
|
|
def delete_offre_recue(id):
|
2022-03-02 15:27:35 +01:00
|
|
|
"""
|
|
|
|
Permet de supprimer une offre reçue
|
|
|
|
"""
|
2022-02-14 19:42:17 +01:00
|
|
|
offre_recue = EntrepriseEnvoiOffre.query.filter_by(
|
|
|
|
id=id, receiver_id=current_user.id
|
2022-02-22 21:52:32 +01:00
|
|
|
).first_or_404(description=f"offre recu {id} inconnue")
|
2022-02-14 19:42:17 +01:00
|
|
|
db.session.delete(offre_recue)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for("entreprises.offres_recues"))
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/expired/<int:id>", methods=["GET", "POST"])
|
2022-03-01 18:45:04 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
|
|
|
def expired(id):
|
2022-03-02 15:27:35 +01:00
|
|
|
"""
|
|
|
|
Permet de rendre expirée et non expirée une offre
|
|
|
|
"""
|
2022-03-01 18:45:04 +01:00
|
|
|
offre = EntrepriseOffre.query.filter_by(id=id).first_or_404(
|
|
|
|
description=f"offre {id} inconnue"
|
|
|
|
)
|
|
|
|
offre.expired = not offre.expired
|
|
|
|
db.session.commit()
|
2022-03-02 15:27:35 +01:00
|
|
|
if offre.expired:
|
|
|
|
flash("L'offre a été rendu expirée")
|
|
|
|
else:
|
|
|
|
flash("L'offre a été rendu non expirée")
|
2022-03-01 18:45:04 +01:00
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id))
|
|
|
|
|
|
|
|
|
2022-04-25 20:49:21 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:id>/add_site",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2022-04-25 20:49:21 +02:00
|
|
|
def add_site(id):
|
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
|
|
|
description=f"entreprise {id} inconnue"
|
|
|
|
)
|
|
|
|
form = SiteCreationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
site = EntrepriseSite(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
nom=form.nom.data.strip(),
|
|
|
|
adresse=form.adresse.data.strip(),
|
|
|
|
codepostal=form.codepostal.data.strip(),
|
|
|
|
ville=form.ville.data.strip(),
|
|
|
|
pays=form.pays.data.strip() if form.pays.data.strip() else "FRANCE",
|
|
|
|
)
|
|
|
|
db.session.add(site)
|
|
|
|
db.session.commit()
|
|
|
|
flash("Le site a été créé et ajouté à la fiche entreprise")
|
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
|
|
|
return render_template(
|
|
|
|
"entreprises/form.html",
|
|
|
|
title="Ajout site",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:id_entreprise>/add_correspondant/<int:id_site>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
|
|
|
def add_correspondant(id_entreprise, id_site):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet d'ajouter un correspondant a une entreprise
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-04-25 20:49:21 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=id_entreprise, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {id_entreprise} inconnue")
|
|
|
|
site = EntrepriseSite.query.filter_by(id=id_site).first_or_404(
|
|
|
|
description=f"site {id_site} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-04-07 02:54:11 +02:00
|
|
|
form = CorrespondantsCreationForm(hidden_entreprise_id=entreprise.id)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
2022-04-07 02:54:11 +02:00
|
|
|
for correspondant_entry in form.correspondants.entries:
|
|
|
|
correspondant = EntrepriseCorrespondant(
|
|
|
|
entreprise_id=entreprise.id,
|
2022-04-25 20:49:21 +02:00
|
|
|
site_id=site.id,
|
2022-04-20 22:37:04 +02:00
|
|
|
civilite=correspondant_entry.civilite.data,
|
2022-04-07 02:54:11 +02:00
|
|
|
nom=correspondant_entry.nom.data.strip(),
|
|
|
|
prenom=correspondant_entry.prenom.data.strip(),
|
|
|
|
telephone=correspondant_entry.telephone.data.strip(),
|
|
|
|
mail=correspondant_entry.mail.data.strip(),
|
|
|
|
poste=correspondant_entry.poste.data.strip(),
|
|
|
|
service=correspondant_entry.service.data.strip(),
|
2022-04-20 22:37:04 +02:00
|
|
|
origine=correspondant_entry.origine.data.strip(),
|
|
|
|
notes=correspondant_entry.notes.data.strip(),
|
2022-04-07 02:54:11 +02:00
|
|
|
)
|
|
|
|
log = EntrepriseLog(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=entreprise.id,
|
|
|
|
text="Création d'un correspondant",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.add(correspondant)
|
|
|
|
db.session.commit()
|
|
|
|
flash("Le correspondant a été ajouté à la fiche entreprise.")
|
2021-12-23 19:28:25 +01:00
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
2022-02-08 16:40:32 +01:00
|
|
|
return render_template(
|
2022-04-07 02:54:11 +02:00
|
|
|
"entreprises/ajout_correspondants.html",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Ajout correspondant",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/edit_correspondant/<int:id>", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2022-03-28 23:44:57 +02:00
|
|
|
def edit_correspondant(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet de modifier un correspondant
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant = EntrepriseCorrespondant.query.filter_by(id=id).first_or_404(
|
|
|
|
description=f"correspondant {id} inconnu"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
form = CorrespondantModificationForm(
|
|
|
|
hidden_entreprise_id=correspondant.entreprise_id,
|
|
|
|
hidden_correspondant_id=correspondant.id,
|
2022-02-07 21:40:58 +01:00
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
2022-04-20 22:37:04 +02:00
|
|
|
correspondant.civilite = form.civilite.data
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant.nom = form.nom.data.strip()
|
|
|
|
correspondant.prenom = form.prenom.data.strip()
|
|
|
|
correspondant.telephone = form.telephone.data.strip()
|
|
|
|
correspondant.mail = form.mail.data.strip()
|
|
|
|
correspondant.poste = form.poste.data.strip()
|
|
|
|
correspondant.service = form.service.data.strip()
|
2022-04-20 22:37:04 +02:00
|
|
|
correspondant.origine = form.origine.data.strip()
|
|
|
|
correspondant.notes = form.notes.data.strip()
|
2021-12-23 19:28:25 +01:00
|
|
|
log = EntrepriseLog(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-03-28 23:44:57 +02:00
|
|
|
object=correspondant.entreprise_id,
|
|
|
|
text="Modification d'un correspondant",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
2022-03-28 23:44:57 +02:00
|
|
|
flash("Le correspondant a été modifié.")
|
2021-12-28 21:20:50 +01:00
|
|
|
return redirect(
|
2022-04-25 20:49:21 +02:00
|
|
|
url_for("entreprises.fiche_entreprise", id=correspondant.entreprise_id)
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
elif request.method == "GET":
|
2022-04-20 22:37:04 +02:00
|
|
|
form.civilite.data = correspondant.civilite
|
2022-03-28 23:44:57 +02:00
|
|
|
form.nom.data = correspondant.nom
|
|
|
|
form.prenom.data = correspondant.prenom
|
|
|
|
form.telephone.data = correspondant.telephone
|
|
|
|
form.mail.data = correspondant.mail
|
|
|
|
form.poste.data = correspondant.poste
|
|
|
|
form.service.data = correspondant.service
|
2022-04-20 22:37:04 +02:00
|
|
|
form.origine.data = correspondant.origine
|
|
|
|
form.notes.data = correspondant.notes
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-02-08 16:40:32 +01:00
|
|
|
"entreprises/form.html",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Modification correspondant",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/delete_correspondant/<int:id>", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2022-03-28 23:44:57 +02:00
|
|
|
def delete_correspondant(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet de supprimer un correspondant
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant = EntrepriseCorrespondant.query.filter_by(id=id).first_or_404(
|
|
|
|
description=f"correspondant {id} inconnu"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
form = SuppressionConfirmationForm()
|
|
|
|
if form.validate_on_submit():
|
2022-04-12 00:21:25 +02:00
|
|
|
db.session.delete(correspondant)
|
|
|
|
log = EntrepriseLog(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
object=correspondant.entreprise_id,
|
|
|
|
text="Suppression d'un correspondant",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("Le correspondant a été supprimé de la fiche entreprise.")
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", id=correspondant.entreprise_id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-04-21 21:18:47 +02:00
|
|
|
"entreprises/confirmation_form.html",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Supression correspondant",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:id>/add_contact", methods=["GET", "POST"])
|
2022-04-05 02:26:43 +02:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
|
|
|
def add_contact(id):
|
|
|
|
"""
|
|
|
|
Permet d'ajouter un contact avec une entreprise
|
|
|
|
"""
|
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
|
|
|
description=f"entreprise {id} inconnue"
|
|
|
|
)
|
2022-04-15 18:16:48 +02:00
|
|
|
form = ContactCreationForm(
|
|
|
|
date=f"{datetime.now().strftime('%Y-%m-%dT%H:%M')}",
|
|
|
|
utilisateur=f"{current_user.nom} {current_user.prenom} ({current_user.user_name})"
|
|
|
|
if current_user.nom and current_user.prenom
|
|
|
|
else "",
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
if form.validate_on_submit():
|
2022-04-15 18:16:48 +02:00
|
|
|
utilisateur_data = form.utilisateur.data.upper().strip()
|
|
|
|
stm = text(
|
|
|
|
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
|
|
|
)
|
|
|
|
utilisateur = (
|
|
|
|
User.query.from_statement(stm)
|
|
|
|
.params(utilisateur_data=utilisateur_data)
|
|
|
|
.first()
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
contact = EntrepriseContact(
|
|
|
|
date=form.date.data,
|
2022-04-15 18:16:48 +02:00
|
|
|
user=utilisateur.id,
|
2022-04-05 02:26:43 +02:00
|
|
|
entreprise=entreprise.id,
|
|
|
|
notes=form.notes.data.strip(),
|
|
|
|
)
|
|
|
|
db.session.add(contact)
|
|
|
|
db.session.commit()
|
2022-04-15 18:16:48 +02:00
|
|
|
return redirect(url_for("entreprises.contacts", id=entreprise.id))
|
2022-04-05 02:26:43 +02:00
|
|
|
return render_template(
|
|
|
|
"entreprises/form.html",
|
|
|
|
title="Ajout contact",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/edit_contact/<int:id>", methods=["GET", "POST"])
|
2022-04-05 02:26:43 +02:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
|
|
|
def edit_contact(id):
|
|
|
|
"""
|
|
|
|
Permet d'editer un contact avec une entreprise
|
|
|
|
"""
|
|
|
|
contact = EntrepriseContact.query.filter_by(id=id).first_or_404(
|
|
|
|
description=f"contact {id} inconnu"
|
|
|
|
)
|
|
|
|
form = ContactModificationForm()
|
|
|
|
if form.validate_on_submit():
|
2022-04-15 18:16:48 +02:00
|
|
|
utilisateur_data = form.utilisateur.data.upper().strip()
|
|
|
|
stm = text(
|
|
|
|
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
|
|
|
)
|
|
|
|
utilisateur = (
|
|
|
|
User.query.from_statement(stm)
|
|
|
|
.params(utilisateur_data=utilisateur_data)
|
|
|
|
.first()
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
contact.date = form.date.data
|
2022-04-15 18:16:48 +02:00
|
|
|
contact.user = utilisateur.id
|
2022-04-05 02:26:43 +02:00
|
|
|
contact.notes = form.notes.data
|
|
|
|
db.session.commit()
|
2022-04-15 18:16:48 +02:00
|
|
|
return redirect(url_for("entreprises.contacts", id=contact.entreprise))
|
2022-04-05 02:26:43 +02:00
|
|
|
elif request.method == "GET":
|
2022-04-15 18:16:48 +02:00
|
|
|
utilisateur = User.query.filter_by(id=contact.user).first()
|
|
|
|
form.date.data = contact.date.strftime("%Y-%m-%dT%H:%M")
|
|
|
|
form.utilisateur.data = (
|
|
|
|
f"{utilisateur.nom} {utilisateur.prenom} ({utilisateur.user_name})"
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
form.notes.data = contact.notes
|
|
|
|
return render_template(
|
|
|
|
"entreprises/form.html",
|
|
|
|
title="Modification contact",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:id>/contacts")
|
2022-04-12 00:21:25 +02:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
2022-04-05 02:26:43 +02:00
|
|
|
def contacts(id):
|
2022-04-12 00:21:25 +02:00
|
|
|
"""
|
|
|
|
Permet d'afficher une page avec la liste des contacts d'une entreprise
|
|
|
|
"""
|
2022-04-05 02:26:43 +02:00
|
|
|
contacts = EntrepriseContact.query.filter_by(entreprise=id).all()
|
|
|
|
return render_template(
|
|
|
|
"entreprises/contacts.html",
|
|
|
|
title="Liste des contacts",
|
|
|
|
contacts=contacts,
|
|
|
|
entreprise_id=id,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:id>/add_stage_apprentissage", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2022-03-29 19:07:59 +02:00
|
|
|
def add_stage_apprentissage(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'ajouter un étudiant ayant réalisé un stage ou une alternance sur la fiche entreprise de l'entreprise
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"entreprise {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
form = StageApprentissageCreationForm()
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
etudiant_nomcomplet = form.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_nomcomplet)
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
formation = etudiant.inscription_courante_date(
|
|
|
|
form.date_debut.data, form.date_fin.data
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
stage_apprentissage = EntrepriseStageApprentissage(
|
2021-12-28 21:20:50 +01:00
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
etudid=etudiant.id,
|
|
|
|
type_offre=form.type_offre.data.strip(),
|
|
|
|
date_debut=form.date_debut.data,
|
|
|
|
date_fin=form.date_fin.data,
|
|
|
|
formation_text=formation.formsemestre.titre if formation else None,
|
|
|
|
formation_scodoc=formation.formsemestre.formsemestre_id
|
|
|
|
if formation
|
|
|
|
else None,
|
2022-03-29 19:07:59 +02:00
|
|
|
notes=form.notes.data.strip(),
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
db.session.add(stage_apprentissage)
|
2021-12-23 19:28:25 +01:00
|
|
|
db.session.commit()
|
|
|
|
flash("L'étudiant a été ajouté sur la fiche entreprise.")
|
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-03-28 23:44:57 +02:00
|
|
|
"entreprises/ajout_stage_apprentissage.html",
|
|
|
|
title="Ajout stage / apprentissage",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/edit_stage_apprentissage/<int:id>", methods=["GET", "POST"]
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2022-03-29 19:07:59 +02:00
|
|
|
def edit_stage_apprentissage(id):
|
2022-03-30 20:17:35 +02:00
|
|
|
"""
|
|
|
|
Permet de modifier un étudiant ayant réalisé un stage ou une alternance sur la fiche entreprise de l'entreprise
|
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
stage_apprentissage = EntrepriseStageApprentissage.query.filter_by(
|
|
|
|
id=id
|
|
|
|
).first_or_404(description=f"stage_apprentissage {id} inconnue")
|
|
|
|
etudiant = Identite.query.filter_by(id=stage_apprentissage.etudid).first_or_404(
|
|
|
|
description=f"etudiant {id} inconnue"
|
|
|
|
)
|
|
|
|
form = StageApprentissageModificationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
etudiant_nomcomplet = form.etudiant.data.upper().strip()
|
|
|
|
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_nomcomplet)
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
formation = etudiant.inscription_courante_date(
|
|
|
|
form.date_debut.data, form.date_fin.data
|
|
|
|
)
|
|
|
|
stage_apprentissage.etudid = etudiant.id
|
|
|
|
stage_apprentissage.type_offre = form.type_offre.data.strip()
|
2022-03-29 19:07:59 +02:00
|
|
|
stage_apprentissage.date_debut = form.date_debut.data
|
|
|
|
stage_apprentissage.date_fin = form.date_fin.data
|
2022-03-28 23:44:57 +02:00
|
|
|
stage_apprentissage.formation_text = (
|
|
|
|
formation.formsemestre.titre if formation else None,
|
|
|
|
)
|
|
|
|
stage_apprentissage.formation_scodoc = (
|
|
|
|
formation.formsemestre.formsemestre_id if formation else None,
|
|
|
|
)
|
2022-03-29 19:07:59 +02:00
|
|
|
stage_apprentissage.notes = form.notes.data.strip()
|
2022-03-28 23:44:57 +02:00
|
|
|
db.session.commit()
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
|
|
|
"entreprises.fiche_entreprise", id=stage_apprentissage.entreprise_id
|
|
|
|
)
|
|
|
|
)
|
|
|
|
elif request.method == "GET":
|
|
|
|
form.etudiant.data = f"{sco_etud.format_nom(etudiant.nom)} {sco_etud.format_prenom(etudiant.prenom)}"
|
|
|
|
form.type_offre.data = stage_apprentissage.type_offre
|
|
|
|
form.date_debut.data = stage_apprentissage.date_debut
|
|
|
|
form.date_fin.data = stage_apprentissage.date_fin
|
2022-03-29 19:07:59 +02:00
|
|
|
form.notes.data = stage_apprentissage.notes
|
2022-03-28 23:44:57 +02:00
|
|
|
return render_template(
|
|
|
|
"entreprises/ajout_stage_apprentissage.html",
|
|
|
|
title="Modification stage / apprentissage",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/delete_stage_apprentissage/<int:id>", methods=["GET", "POST"]
|
|
|
|
)
|
2022-04-12 00:21:25 +02:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2022-03-29 19:07:59 +02:00
|
|
|
def delete_stage_apprentissage(id):
|
2022-03-30 20:17:35 +02:00
|
|
|
"""
|
|
|
|
Permet de supprimer un étudiant ayant réalisé un stage ou une alternance sur la fiche entreprise de l'entreprise
|
|
|
|
"""
|
2022-03-29 19:07:59 +02:00
|
|
|
stage_apprentissage = EntrepriseStageApprentissage.query.filter_by(
|
|
|
|
id=id
|
|
|
|
).first_or_404(description=f"stage_apprentissage {id} inconnu")
|
|
|
|
form = SuppressionConfirmationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(stage_apprentissage)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
|
|
|
"entreprises.fiche_entreprise", id=stage_apprentissage.entreprise_id
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return render_template(
|
2022-04-21 21:18:47 +02:00
|
|
|
"entreprises/confirmation_form.html",
|
2022-03-29 19:07:59 +02:00
|
|
|
title="Supression stage/apprentissage",
|
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2022-03-29 19:07:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/envoyer_offre/<int:id>", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesSend)
|
2021-12-23 23:21:47 +01:00
|
|
|
def envoyer_offre(id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet d'envoyer une offre à un utilisateur ScoDoc
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
offre = EntrepriseOffre.query.filter_by(id=id).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"offre {id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-23 23:21:47 +01:00
|
|
|
form = EnvoiOffreForm()
|
|
|
|
if form.validate_on_submit():
|
2022-04-05 23:01:38 +02:00
|
|
|
for responsable in form.responsables.entries:
|
|
|
|
if responsable.data.strip():
|
|
|
|
responsable_data = responsable.data.upper().strip()
|
2022-03-30 20:17:35 +02: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()
|
|
|
|
)
|
|
|
|
envoi_offre = EntrepriseEnvoiOffre(
|
|
|
|
sender_id=current_user.id,
|
|
|
|
receiver_id=responsable.id,
|
|
|
|
offre_id=offre.id,
|
|
|
|
)
|
|
|
|
db.session.add(envoi_offre)
|
2022-04-07 02:54:11 +02:00
|
|
|
db.session.commit()
|
2022-03-30 20:17:35 +02:00
|
|
|
flash(f"L'offre a été envoyé à {responsable.get_nomplogin()}.")
|
2021-12-24 16:07:36 +01:00
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id))
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2022-02-08 16:40:32 +01:00
|
|
|
"entreprises/envoi_offre_form.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Envoyer une offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 23:21:47 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
@bp.route("/etudiants")
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-23 19:28:25 +01:00
|
|
|
def json_etudiants():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de récuperer un JSON avec tous les étudiants
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
if request.args.get("term") is None:
|
2021-12-30 19:37:46 +01:00
|
|
|
abort(400)
|
2021-12-28 21:20:50 +01:00
|
|
|
term = request.args.get("term").strip()
|
2021-12-23 19:28:25 +01:00
|
|
|
etudiants = Identite.query.filter(Identite.nom.ilike(f"%{term}%")).all()
|
|
|
|
list = []
|
|
|
|
for etudiant in etudiants:
|
2022-02-10 21:17:22 +01:00
|
|
|
content = {}
|
2021-12-23 19:28:25 +01:00
|
|
|
value = f"{sco_etud.format_nom(etudiant.nom)} {sco_etud.format_prenom(etudiant.prenom)}"
|
|
|
|
if etudiant.inscription_courante() is not None:
|
|
|
|
content = {
|
|
|
|
"id": f"{etudiant.id}",
|
|
|
|
"value": value,
|
2021-12-28 21:20:50 +01:00
|
|
|
"info": f"{etudiant.inscription_courante().formsemestre.titre}",
|
2021-12-23 19:28:25 +01:00
|
|
|
}
|
|
|
|
else:
|
2021-12-28 21:20:50 +01:00
|
|
|
content = {"id": f"{etudiant.id}", "value": value}
|
2021-12-23 19:28:25 +01:00
|
|
|
list.append(content)
|
|
|
|
return jsonify(results=list)
|
2021-12-28 21:20:50 +01:00
|
|
|
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
@bp.route("/responsables")
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-23 19:28:25 +01:00
|
|
|
def json_responsables():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet de récuperer un JSON avec tous les utilisateurs ScoDoc
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
if request.args.get("term") is None:
|
2021-12-30 19:37:46 +01:00
|
|
|
abort(400)
|
2021-12-28 21:20:50 +01:00
|
|
|
term = request.args.get("term").strip()
|
|
|
|
responsables = User.query.filter(
|
|
|
|
User.nom.ilike(f"%{term}%"), User.nom.is_not(None), User.prenom.is_not(None)
|
|
|
|
).all()
|
2021-12-23 19:28:25 +01:00
|
|
|
list = []
|
2022-02-10 21:17:22 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
for responsable in responsables:
|
2022-02-10 21:17:22 +01:00
|
|
|
content = {}
|
2021-12-23 19:28:25 +01:00
|
|
|
value = f"{responsable.get_nomplogin()}"
|
2021-12-28 21:20:50 +01:00
|
|
|
content = {"id": f"{responsable.id}", "value": value, "info": ""}
|
2021-12-23 19:28:25 +01:00
|
|
|
list.append(content)
|
2021-12-24 18:10:19 +01:00
|
|
|
return jsonify(results=list)
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-24 18:10:19 +01:00
|
|
|
@bp.route("/export_entreprises")
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesExport)
|
2021-12-24 18:10:19 +01:00
|
|
|
def export_entreprises():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'exporter la liste des entreprises sous format excel (.xlsx)
|
|
|
|
"""
|
2022-01-27 16:28:28 +01:00
|
|
|
entreprises = Entreprise.query.filter_by(visible=True).all()
|
2021-12-27 11:48:58 +01:00
|
|
|
if entreprises:
|
2022-02-22 21:52:32 +01:00
|
|
|
keys = ["siret", "nom_entreprise", "adresse", "ville", "code_postal", "pays"]
|
2021-12-27 11:48:58 +01:00
|
|
|
titles = keys[:]
|
2021-12-28 21:20:50 +01:00
|
|
|
L = [
|
2021-12-28 21:26:36 +01:00
|
|
|
[entreprise.to_dict().get(k, "") for k in keys]
|
2021-12-28 21:20:50 +01:00
|
|
|
for entreprise in entreprises
|
|
|
|
]
|
2022-02-10 21:17:22 +01:00
|
|
|
title = "Entreprises"
|
2021-12-27 11:48:58 +01:00
|
|
|
xlsx = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title)
|
|
|
|
filename = title
|
|
|
|
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
|
|
|
else:
|
2022-04-12 00:21:25 +02:00
|
|
|
flash("Aucune entreprise dans la base.")
|
|
|
|
return redirect(url_for("entreprises.index"))
|
2021-12-27 11:48:58 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/import_entreprises/get_import_entreprises_file_sample")
|
2022-02-07 18:39:32 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesExport)
|
|
|
|
def get_import_entreprises_file_sample():
|
2022-02-10 21:17:22 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet de récupérer un fichier exemple vide pour pouvoir importer des entreprises
|
2022-02-10 21:17:22 +01:00
|
|
|
"""
|
2022-02-07 18:39:32 +01:00
|
|
|
keys = [
|
|
|
|
"siret",
|
|
|
|
"nom_entreprise",
|
|
|
|
"adresse",
|
|
|
|
"ville",
|
2022-02-22 21:52:32 +01:00
|
|
|
"code_postal",
|
2022-02-07 18:39:32 +01:00
|
|
|
"pays",
|
|
|
|
]
|
|
|
|
titles = keys[:]
|
|
|
|
title = "ImportEntreprises"
|
2022-02-22 21:52:32 +01:00
|
|
|
xlsx = sco_excel.excel_simple_table(titles=titles, sheet_name="Entreprises")
|
2022-02-07 18:39:32 +01:00
|
|
|
filename = title
|
|
|
|
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/import_entreprises", methods=["GET", "POST"])
|
|
|
|
@permission_required(Permission.RelationsEntreprisesExport)
|
|
|
|
def import_entreprises():
|
2022-02-08 16:40:32 +01:00
|
|
|
"""
|
|
|
|
Permet d'importer des entreprises a l'aide d'un fichier excel (.xlsx)
|
|
|
|
"""
|
2022-02-10 21:17:22 +01:00
|
|
|
form = ImportForm()
|
2022-02-07 18:39:32 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
file = form.fichier.data
|
2022-02-11 19:18:01 +01:00
|
|
|
file_path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR, "tmp", secure_filename(file.filename)
|
|
|
|
)
|
2022-02-08 19:13:45 +01:00
|
|
|
file.save(file_path)
|
|
|
|
data = sco_excel.excel_file_to_list(file_path)
|
|
|
|
os.remove(file_path)
|
|
|
|
entreprises_import = []
|
2022-02-09 20:09:14 +01:00
|
|
|
siret_list = []
|
|
|
|
ligne = 0
|
2022-02-22 21:52:32 +01:00
|
|
|
titles = ["siret", "nom_entreprise", "adresse", "ville", "code_postal", "pays"]
|
2022-02-10 21:17:22 +01:00
|
|
|
if data[1][0] != titles:
|
|
|
|
flash("Veuillez utilisez la feuille excel à remplir")
|
|
|
|
return render_template(
|
|
|
|
"entreprises/import_entreprises.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Importation entreprises",
|
2022-02-10 21:17:22 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2022-02-08 19:13:45 +01:00
|
|
|
for entreprise_data in data[1][1:]:
|
2022-02-09 20:09:14 +01:00
|
|
|
ligne += 1
|
|
|
|
if (
|
2022-02-15 18:24:10 +01:00
|
|
|
are.verif_entreprise_data(entreprise_data)
|
2022-04-13 20:59:26 +02:00
|
|
|
and entreprise_data[0].replace(" ", "") not in siret_list
|
2022-02-09 20:09:14 +01:00
|
|
|
):
|
2022-04-13 20:59:26 +02:00
|
|
|
siret_list.append(entreprise_data[0].replace(" ", ""))
|
2022-02-08 19:13:45 +01:00
|
|
|
entreprise = Entreprise(
|
2022-04-12 00:21:25 +02:00
|
|
|
siret=entreprise_data[0].replace(" ", ""),
|
2022-04-13 20:59:26 +02:00
|
|
|
nom=entreprise_data[1].strip(),
|
|
|
|
adresse=entreprise_data[2].strip(),
|
|
|
|
ville=entreprise_data[3].strip(),
|
|
|
|
codepostal=entreprise_data[4].strip(),
|
|
|
|
pays=entreprise_data[5].strip(),
|
2022-02-09 20:09:14 +01:00
|
|
|
visible=True,
|
2022-02-08 19:13:45 +01:00
|
|
|
)
|
|
|
|
entreprises_import.append(entreprise)
|
2022-02-09 20:09:14 +01:00
|
|
|
else:
|
|
|
|
flash(f"Erreur lors de l'importation (ligne {ligne})")
|
|
|
|
return render_template(
|
|
|
|
"entreprises/import_entreprises.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Importation entreprises",
|
2022-02-09 20:09:14 +01:00
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(entreprises_import) > 0:
|
|
|
|
for entreprise in entreprises_import:
|
|
|
|
db.session.add(entreprise)
|
2022-02-14 19:42:17 +01:00
|
|
|
log = EntrepriseLog(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
text=f"Importation de {len(entreprises_import)} entreprise(s)",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-02-09 20:09:14 +01:00
|
|
|
db.session.commit()
|
|
|
|
flash(f"Importation réussie de {len(entreprises_import)} entreprise(s)")
|
|
|
|
return render_template(
|
|
|
|
"entreprises/import_entreprises.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Importation entreprises",
|
2022-02-09 20:09:14 +01:00
|
|
|
form=form,
|
|
|
|
entreprises_import=entreprises_import,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
flash('Feuille "Entreprises" vide')
|
|
|
|
|
2022-02-07 18:39:32 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/import_entreprises.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Importation entreprises",
|
2022-02-07 18:39:32 +01:00
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-03-28 23:44:57 +02:00
|
|
|
@bp.route("/export_correspondants")
|
2022-01-26 18:46:21 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesExport)
|
2022-03-28 23:44:57 +02:00
|
|
|
def export_correspondants():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet d'exporter la liste des correspondants sous format excel (.xlsx)
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants = (
|
|
|
|
db.session.query(EntrepriseCorrespondant)
|
|
|
|
.join(Entreprise, EntrepriseCorrespondant.entreprise_id == Entreprise.id)
|
2022-02-03 11:49:16 +01:00
|
|
|
.filter_by(visible=True)
|
|
|
|
.all()
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
if correspondants:
|
2022-02-10 21:17:22 +01:00
|
|
|
keys = [
|
2022-04-22 11:27:17 +02:00
|
|
|
"civilite",
|
2022-02-10 21:17:22 +01:00
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"telephone",
|
|
|
|
"mail",
|
|
|
|
"poste",
|
|
|
|
"service",
|
2022-04-22 11:27:17 +02:00
|
|
|
"origine",
|
|
|
|
"notes",
|
2022-02-22 21:52:32 +01:00
|
|
|
"entreprise_siret",
|
2022-02-10 21:17:22 +01:00
|
|
|
]
|
2021-12-27 11:48:58 +01:00
|
|
|
titles = keys[:]
|
2022-03-28 23:44:57 +02:00
|
|
|
L = [
|
|
|
|
[correspondant.to_dict().get(k, "") for k in keys]
|
|
|
|
for correspondant in correspondants
|
|
|
|
]
|
|
|
|
title = "Correspondants"
|
2021-12-27 11:48:58 +01:00
|
|
|
xlsx = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title)
|
|
|
|
filename = title
|
|
|
|
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
2021-12-27 19:00:38 +01:00
|
|
|
else:
|
2022-04-12 00:21:25 +02:00
|
|
|
flash("Aucun correspondant dans la base.")
|
|
|
|
return redirect(url_for("entreprises.correspondants"))
|
2021-12-27 19:00:38 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/import_correspondants/get_import_correspondants_file_sample")
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesExport)
|
2022-03-28 23:44:57 +02:00
|
|
|
def get_import_correspondants_file_sample():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet de récupérer un fichier exemple vide pour pouvoir importer des correspondants
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-02-10 21:17:22 +01:00
|
|
|
keys = [
|
2022-04-22 11:27:17 +02:00
|
|
|
"civilite",
|
2022-02-10 21:17:22 +01:00
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"telephone",
|
|
|
|
"mail",
|
|
|
|
"poste",
|
|
|
|
"service",
|
2022-04-22 11:27:17 +02:00
|
|
|
"origine",
|
|
|
|
"notes",
|
2022-02-22 21:52:32 +01:00
|
|
|
"entreprise_siret",
|
2022-02-10 21:17:22 +01:00
|
|
|
]
|
|
|
|
titles = keys[:]
|
2022-03-28 23:44:57 +02:00
|
|
|
title = "ImportCorrespondants"
|
|
|
|
xlsx = sco_excel.excel_simple_table(titles=titles, sheet_name="Correspondants")
|
2022-02-10 21:17:22 +01:00
|
|
|
filename = title
|
|
|
|
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
|
|
|
|
|
|
|
|
2022-03-28 23:44:57 +02:00
|
|
|
@bp.route("/import_correspondants", methods=["GET", "POST"])
|
2022-02-10 21:17:22 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesExport)
|
2022-03-28 23:44:57 +02:00
|
|
|
def import_correspondants():
|
2022-02-10 21:17:22 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet d'importer des correspondants a l'aide d'un fichier excel (.xlsx)
|
2022-02-10 21:17:22 +01:00
|
|
|
"""
|
|
|
|
form = ImportForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
file = form.fichier.data
|
2022-02-11 19:18:01 +01:00
|
|
|
file_path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR, "tmp", secure_filename(file.filename)
|
|
|
|
)
|
2022-02-10 21:17:22 +01:00
|
|
|
file.save(file_path)
|
|
|
|
data = sco_excel.excel_file_to_list(file_path)
|
|
|
|
os.remove(file_path)
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants_import = []
|
|
|
|
correspondant_list = []
|
2022-02-10 21:17:22 +01:00
|
|
|
ligne = 0
|
|
|
|
titles = [
|
2022-04-22 11:27:17 +02:00
|
|
|
"civilite",
|
2021-12-29 19:40:57 +01:00
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"telephone",
|
|
|
|
"mail",
|
|
|
|
"poste",
|
|
|
|
"service",
|
2022-04-22 11:27:17 +02:00
|
|
|
"origine",
|
|
|
|
"notes",
|
2022-02-22 21:52:32 +01:00
|
|
|
"entreprise_siret",
|
2021-12-29 19:40:57 +01:00
|
|
|
]
|
2022-02-10 21:17:22 +01:00
|
|
|
if data[1][0] != titles:
|
|
|
|
flash("Veuillez utilisez la feuille excel à remplir")
|
|
|
|
return render_template(
|
2022-03-28 23:44:57 +02:00
|
|
|
"entreprises/import_correspondants.html",
|
|
|
|
title="Importation correspondants",
|
2022-02-10 21:17:22 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
for correspondant_data in data[1][1:]:
|
2022-02-10 21:17:22 +01:00
|
|
|
ligne += 1
|
|
|
|
if (
|
2022-03-28 23:44:57 +02:00
|
|
|
are.verif_correspondant_data(correspondant_data)
|
|
|
|
and (
|
2022-04-13 20:59:26 +02:00
|
|
|
correspondant_data[1].strip(),
|
2022-04-22 11:27:17 +02:00
|
|
|
correspondant_data[2].strip(),
|
|
|
|
correspondant_data[9].strip(),
|
2022-03-28 23:44:57 +02:00
|
|
|
)
|
|
|
|
not in correspondant_list
|
2022-02-10 21:17:22 +01:00
|
|
|
):
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant_list.append(
|
|
|
|
(
|
2022-04-13 20:59:26 +02:00
|
|
|
correspondant_data[1].strip(),
|
2022-04-22 11:27:17 +02:00
|
|
|
correspondant_data[2].strip(),
|
|
|
|
correspondant_data[9].strip(),
|
2022-03-28 23:44:57 +02:00
|
|
|
)
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
2022-04-22 11:27:17 +02:00
|
|
|
siret=correspondant_data[9].strip()
|
2022-04-05 02:26:43 +02:00
|
|
|
).first()
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant = EntrepriseCorrespondant(
|
2022-04-22 11:27:17 +02:00
|
|
|
civilite=correspondant_data[0].strip(),
|
|
|
|
nom=correspondant_data[1].strip(),
|
|
|
|
prenom=correspondant_data[2].strip(),
|
|
|
|
telephone=correspondant_data[3].strip(),
|
|
|
|
mail=correspondant_data[4].strip(),
|
|
|
|
poste=correspondant_data[5].strip(),
|
|
|
|
service=correspondant_data[6].strip(),
|
|
|
|
origine=correspondant_data[7].strip(),
|
|
|
|
notes=correspondant_data[8].strip(),
|
2022-04-05 02:26:43 +02:00
|
|
|
entreprise_id=entreprise.id,
|
2022-02-10 21:17:22 +01:00
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants_import.append(correspondant)
|
2022-02-10 21:17:22 +01:00
|
|
|
else:
|
|
|
|
flash(f"Erreur lors de l'importation (ligne {ligne})")
|
|
|
|
return render_template(
|
2022-03-28 23:44:57 +02:00
|
|
|
"entreprises/import_correspondants.html",
|
|
|
|
title="Importation correspondants",
|
2022-02-10 21:17:22 +01:00
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
2022-03-28 23:44:57 +02:00
|
|
|
if len(correspondants_import) > 0:
|
|
|
|
for correspondant in correspondants_import:
|
|
|
|
db.session.add(correspondant)
|
2022-02-14 19:42:17 +01:00
|
|
|
log = EntrepriseLog(
|
|
|
|
authenticated_user=current_user.user_name,
|
2022-03-28 23:44:57 +02:00
|
|
|
text=f"Importation de {len(correspondants_import)} correspondant(s)",
|
2022-02-14 19:42:17 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-02-10 21:17:22 +01:00
|
|
|
db.session.commit()
|
2022-03-28 23:44:57 +02:00
|
|
|
flash(
|
|
|
|
f"Importation réussie de {len(correspondants_import)} correspondant(s)"
|
|
|
|
)
|
2022-02-10 21:17:22 +01:00
|
|
|
return render_template(
|
2022-03-28 23:44:57 +02:00
|
|
|
"entreprises/import_correspondants.html",
|
|
|
|
title="Importation correspondants",
|
2022-02-10 21:17:22 +01:00
|
|
|
form=form,
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants_import=correspondants_import,
|
2022-02-10 21:17:22 +01:00
|
|
|
)
|
|
|
|
else:
|
2022-03-28 23:44:57 +02:00
|
|
|
flash('Feuille "Correspondants" vide')
|
2022-02-10 21:17:22 +01:00
|
|
|
return render_template(
|
2022-03-28 23:44:57 +02:00
|
|
|
"entreprises/import_correspondants.html",
|
|
|
|
title="Importation correspondants",
|
2022-02-10 21:17:22 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2021-12-29 19:40:57 +01:00
|
|
|
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
@bp.route(
|
|
|
|
"/get_offre_file/<int:entreprise_id>/<int:offre_id>/<string:filedir>/<string:filename>"
|
|
|
|
)
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesView)
|
2021-12-28 21:20:50 +01:00
|
|
|
def get_offre_file(entreprise_id, offre_id, filedir, filename):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de télécharger un fichier d'une offre
|
|
|
|
"""
|
2021-12-28 21:20:50 +01:00
|
|
|
if os.path.isfile(
|
|
|
|
os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{entreprise_id}",
|
|
|
|
f"{offre_id}",
|
|
|
|
f"{filedir}",
|
|
|
|
f"{filename}",
|
|
|
|
)
|
|
|
|
):
|
|
|
|
return send_file(
|
|
|
|
os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{entreprise_id}",
|
|
|
|
f"{offre_id}",
|
|
|
|
f"{filedir}",
|
|
|
|
f"{filename}",
|
|
|
|
),
|
|
|
|
as_attachment=True,
|
|
|
|
)
|
2021-12-27 11:48:58 +01:00
|
|
|
else:
|
2022-02-21 20:22:27 +01:00
|
|
|
abort(404, description=f"fichier {filename} inconnu")
|
2021-12-28 21:20:50 +01:00
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route("/fiche_entreprise/add_offre_file/<int:offre_id>", methods=["GET", "POST"])
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-28 21:20:50 +01:00
|
|
|
def add_offre_file(offre_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'ajouter un fichier à une offre
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
offre = EntrepriseOffre.query.filter_by(id=offre_id).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"offre {offre_id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
form = AjoutFichierForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
date = f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}"
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{offre.entreprise_id}",
|
|
|
|
f"{offre.id}",
|
|
|
|
f"{date}",
|
|
|
|
)
|
|
|
|
os.makedirs(path)
|
|
|
|
file = form.fichier.data
|
|
|
|
filename = secure_filename(file.filename)
|
|
|
|
file.save(os.path.join(path, filename))
|
|
|
|
flash("Le fichier a été ajouté a l'offre.")
|
|
|
|
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id))
|
|
|
|
return render_template(
|
2022-02-08 16:40:32 +01:00
|
|
|
"entreprises/form.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Ajout fichier à une offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/delete_offre_file/<int:offre_id>/<string:filedir>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2022-01-26 18:42:48 +01:00
|
|
|
@permission_required(Permission.RelationsEntreprisesChange)
|
2021-12-28 21:20:50 +01:00
|
|
|
def delete_offre_file(offre_id, filedir):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de supprimer un fichier d'une offre
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
offre = EntrepriseOffre.query.filter_by(id=offre_id).first_or_404(
|
2022-02-22 21:52:32 +01:00
|
|
|
description=f"offre {offre_id} inconnue"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
form = SuppressionConfirmationForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{offre.entreprise_id}",
|
|
|
|
f"{offre_id}",
|
|
|
|
f"{filedir}",
|
|
|
|
)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
|
|
|
flash("Le fichier relié à l'offre a été supprimé.")
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", id=offre.entreprise_id)
|
|
|
|
)
|
|
|
|
return render_template(
|
2022-04-21 21:18:47 +02:00
|
|
|
"entreprises/confirmation_form.html",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Suppression fichier d'une offre",
|
2021-12-28 21:20:50 +01:00
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
2022-02-22 21:52:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/preferences", methods=["GET", "POST"])
|
|
|
|
@permission_required(Permission.RelationsEntreprisesValidate)
|
|
|
|
def preferences():
|
2022-03-02 15:27:35 +01:00
|
|
|
"""
|
|
|
|
Permet d'afficher la page des préférences du module gestion des relations entreprises
|
|
|
|
"""
|
2022-02-22 21:52:32 +01:00
|
|
|
form = PreferencesForm()
|
|
|
|
if form.validate_on_submit():
|
2022-02-23 19:12:26 +01:00
|
|
|
EntreprisePreferences.set_email_notifications(form.mail_entreprise.data.strip())
|
|
|
|
EntreprisePreferences.set_check_siret(int(form.check_siret.data))
|
2022-02-22 21:52:32 +01:00
|
|
|
return redirect(url_for("entreprises.index"))
|
|
|
|
elif request.method == "GET":
|
2022-02-23 19:12:26 +01:00
|
|
|
form.mail_entreprise.data = EntreprisePreferences.get_email_notifications()
|
|
|
|
form.check_siret.data = int(EntreprisePreferences.get_check_siret())
|
2022-02-22 21:52:32 +01:00
|
|
|
return render_template(
|
|
|
|
"entreprises/preferences.html",
|
|
|
|
title="Préférences",
|
|
|
|
form=form,
|
|
|
|
)
|