2022-03-02 16:45:47 +01:00
|
|
|
|
##############################################" Formations ############################################################
|
|
|
|
|
from flask import jsonify
|
|
|
|
|
|
|
|
|
|
from app import models
|
|
|
|
|
from app.api import bp
|
|
|
|
|
from app.api.errors import error_response
|
2022-04-14 14:56:36 +02:00
|
|
|
|
from app.api.auth import token_auth, token_permission_required
|
2022-03-02 16:45:47 +01:00
|
|
|
|
from app.scodoc.sco_formations import formation_export
|
|
|
|
|
from app.scodoc.sco_moduleimpl import moduleimpl_list
|
2022-03-04 17:16:08 +01:00
|
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/formations", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def formations():
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des formations
|
|
|
|
|
"""
|
|
|
|
|
# Récupération de toutes les formations
|
|
|
|
|
list_formations = models.Formation.query.all()
|
|
|
|
|
|
|
|
|
|
# Mise en forme des données
|
|
|
|
|
data = [d.to_dict() for d in list_formations]
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/formations/<int:formation_id>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def formations_by_id(formation_id: int):
|
|
|
|
|
"""
|
|
|
|
|
Retourne une formation en fonction d'un id donné
|
|
|
|
|
|
|
|
|
|
formation_id : l'id d'une formation
|
|
|
|
|
"""
|
|
|
|
|
# Récupération de la formation
|
|
|
|
|
forma = models.Formation.query.filter_by(id=formation_id).first()
|
|
|
|
|
|
|
|
|
|
# Mise en forme des données
|
|
|
|
|
data = [d.to_dict() for d in forma]
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/formations/formation_export/<int:formation_id>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def formation_export_by_formation_id(formation_id: int, export_ids=False):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la formation, avec UE, matières, modules
|
|
|
|
|
"""
|
|
|
|
|
# Fonction utilité : app.scodoc.sco_formations.formation_export()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Utilisation de la fonction formation_export
|
|
|
|
|
data = formation_export(formation_id)
|
|
|
|
|
except ValueError:
|
2022-04-25 15:25:45 +02:00
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel. \n"
|
|
|
|
|
"Veillez vérifier la conformité du 'formation_id'",
|
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/formations/apo/<string:etape_apo>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def formsemestre_apo(etape_apo: int):
|
|
|
|
|
"""
|
|
|
|
|
Retourne les informations sur les formsemestres
|
|
|
|
|
|
|
|
|
|
etape_apo : l'id d'une étape apogée
|
|
|
|
|
"""
|
|
|
|
|
# Récupération des formsemestres
|
|
|
|
|
apos = models.FormSemestreEtape.query.filter_by(etape_apo=etape_apo).all()
|
|
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
# Filtre les formsemestres correspondant + mise en forme des données
|
|
|
|
|
for apo in apos:
|
|
|
|
|
formsem = models.FormSemestre.query.filter_by(id=apo["formsemestre_id"]).first()
|
|
|
|
|
data.append(formsem.to_dict())
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
# return error_response(501, message="Not implemented")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/formations/moduleimpl/<int:moduleimpl_id>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def moduleimpls(moduleimpl_id: int):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des moduleimpl
|
|
|
|
|
|
|
|
|
|
moduleimpl_id : l'id d'un moduleimpl
|
|
|
|
|
"""
|
|
|
|
|
# Récupération des tous les moduleimpl
|
|
|
|
|
list_moduleimpls = models.ModuleImpl.query.filter_by(id=moduleimpl_id).all()
|
|
|
|
|
|
|
|
|
|
# Mise en forme des données
|
|
|
|
|
data = list_moduleimpls[0].to_dict()
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
@bp.route(
|
|
|
|
|
"/formations/moduleimpl/<int:moduleimpl_id>/formsemestre/<int:formsemestre_id>",
|
|
|
|
|
methods=["GET"],
|
|
|
|
|
)
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def moduleimpls_sem(moduleimpl_id: int, formsemestre_id: int):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des moduleimpl d'un semestre
|
|
|
|
|
|
|
|
|
|
moduleimpl_id : l'id d'un moduleimpl
|
|
|
|
|
formsemestre_id : l'id d'un formsemestre
|
|
|
|
|
"""
|
|
|
|
|
# Fonction utilisée : app.scodoc.sco_moduleimpl.moduleimpl_list()
|
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
# Utilisation de la fonction moduleimpl_list
|
|
|
|
|
data = moduleimpl_list(moduleimpl_id, formsemestre_id)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
if len(data) == 0:
|
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel. \n"
|
|
|
|
|
"Aucun moduleimpl ne correspond au 'moduleimpl_id' ou "
|
|
|
|
|
"'formsemestre_id' renseigné",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|