2022-03-02 16:45:47 +01:00
|
|
|
############################################### Departements ##########################################################
|
2022-04-21 15:57:02 +02:00
|
|
|
import app
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
from app import models
|
|
|
|
from app.api import bp
|
2022-04-26 15:23:10 +02:00
|
|
|
from app.api.auth import token_permission_required
|
2022-03-02 16:45:47 +01:00
|
|
|
from app.api.errors import error_response
|
2022-03-04 17:16:08 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
from flask import jsonify
|
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
@bp.route("/departements", methods=["GET"])
|
2022-04-13 12:39:10 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
def departements():
|
|
|
|
"""
|
|
|
|
Retourne la liste des ids de départements visibles
|
|
|
|
|
2022-04-28 09:06:20 +02:00
|
|
|
Exemple de résultat :
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"acronym": "TAPI",
|
|
|
|
"description": null,
|
|
|
|
"visible": true,
|
|
|
|
"date_creation": "Fri, 15 Apr 2022 12:19:28 GMT"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"acronym": "MMI",
|
|
|
|
"description": null,
|
|
|
|
"visible": false,
|
|
|
|
"date_creation": "Fri, 18 Apr 2022 11:20:8 GMT"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
# Récupération de tous les départements
|
2022-04-28 09:06:20 +02:00
|
|
|
depts = models.Departement.query.all()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-04-28 09:06:20 +02:00
|
|
|
# Mise en place de la liste avec tous les départements
|
|
|
|
data = [d.to_dict() for d in depts]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-04-28 09:06:20 +02:00
|
|
|
return jsonify(data)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-03-03 16:25:29 +01:00
|
|
|
@bp.route("/departements/<string:dept>/etudiants/liste", methods=["GET"])
|
2022-04-13 12:39:10 +02:00
|
|
|
@bp.route(
|
|
|
|
"/departements/<string:dept>/etudiants/liste/<int:formsemestre_id>", methods=["GET"]
|
|
|
|
)
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-04 17:16:08 +01:00
|
|
|
def liste_etudiants(dept: str, formsemestre_id=None):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
Retourne la liste des étudiants d'un département
|
|
|
|
|
|
|
|
dept: l'acronym d'un département
|
|
|
|
formsemestre_id: l'id d'un formesemestre
|
|
|
|
|
|
|
|
Exemple de résultat :
|
2022-04-27 15:29:09 +02:00
|
|
|
[
|
|
|
|
{
|
2022-03-02 16:45:47 +01:00
|
|
|
"civilite": "X",
|
|
|
|
"code_ine": null,
|
|
|
|
"code_nip": null,
|
|
|
|
"date_naissance": null,
|
|
|
|
"email": null,
|
|
|
|
"emailperso": null,
|
|
|
|
"etudid": 18,
|
|
|
|
"nom": "MOREL",
|
|
|
|
"prenom": "JACQUES"
|
2022-04-27 15:29:09 +02:00
|
|
|
},
|
|
|
|
{
|
2022-03-02 16:45:47 +01:00
|
|
|
"civilite": "X",
|
|
|
|
"code_ine": null,
|
|
|
|
"code_nip": null,
|
|
|
|
"date_naissance": null,
|
|
|
|
"email": null,
|
|
|
|
"emailperso": null,
|
|
|
|
"etudid": 19,
|
|
|
|
"nom": "FOURNIER",
|
|
|
|
"prenom": "ANNE"
|
2022-04-27 15:29:09 +02:00
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
# Si le formsemestre_id a été renseigné
|
|
|
|
if formsemestre_id is not None:
|
2022-03-03 16:25:29 +01:00
|
|
|
# Récupération du formsemestre
|
2022-04-26 17:12:30 +02:00
|
|
|
formsemestre = models.FormSemestre.query.filter_by(
|
|
|
|
id=formsemestre_id
|
|
|
|
).first_or_404()
|
2022-03-03 16:25:29 +01:00
|
|
|
# Récupération du département
|
|
|
|
departement = formsemestre.departement
|
|
|
|
|
|
|
|
# Si le formsemestre_id n'a pas été renseigné
|
|
|
|
else:
|
|
|
|
# Récupération du formsemestre
|
2022-04-26 15:23:10 +02:00
|
|
|
departement = models.Departement.query.filter_by(acronym=dept).first_or_404()
|
2022-03-03 16:25:29 +01:00
|
|
|
|
2022-04-22 16:22:10 +02:00
|
|
|
# Récupération des étudiants
|
|
|
|
etudiants = departement.etudiants.all()
|
|
|
|
|
|
|
|
# Mise en forme des données
|
|
|
|
list_etu = [etu.to_dict_bul(include_urls=False) for etu in etudiants]
|
2022-03-03 16:25:29 +01:00
|
|
|
|
|
|
|
return jsonify(list_etu)
|
|
|
|
|
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
@bp.route("/departements/<string:dept>/semestres_courants", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
def liste_semestres_courant(dept: str):
|
|
|
|
"""
|
|
|
|
Liste des semestres actifs d'un départements donné
|
|
|
|
|
|
|
|
dept: l'acronym d'un département
|
|
|
|
|
|
|
|
Exemple de résultat :
|
2022-04-27 15:29:09 +02:00
|
|
|
[
|
|
|
|
{
|
2022-05-04 16:28:34 +02:00
|
|
|
"date_fin": "31/08/2022",
|
|
|
|
"resp_can_edit": false,
|
|
|
|
"dept_id": 1,
|
|
|
|
"etat": true,
|
|
|
|
"resp_can_change_ens": true,
|
|
|
|
"id": 1,
|
|
|
|
"modalite": "FI",
|
|
|
|
"ens_can_edit_eval": false,
|
|
|
|
"formation_id": 1,
|
|
|
|
"gestion_compensation": false,
|
|
|
|
"elt_sem_apo": null,
|
|
|
|
"semestre_id": 1,
|
|
|
|
"bul_hide_xml": false,
|
|
|
|
"elt_annee_apo": null,
|
|
|
|
"titre": "Semestre test",
|
|
|
|
"block_moyennes": false,
|
|
|
|
"scodoc7_id": null,
|
|
|
|
"date_debut": "01/09/2021",
|
|
|
|
"gestion_semestrielle": false,
|
|
|
|
"bul_bgcolor": "white",
|
|
|
|
"formsemestre_id": 1,
|
|
|
|
"titre_num": "Semestre test semestre 1",
|
|
|
|
"date_debut_iso": "2021-09-01",
|
|
|
|
"date_fin_iso": "2022-08-31",
|
|
|
|
"responsables": []
|
|
|
|
"titre_court": BUT MMI
|
2022-04-27 15:29:09 +02:00
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
# Récupération des départements comportant l'acronym mit en paramètre
|
2022-04-26 15:23:10 +02:00
|
|
|
dept = models.Departement.query.filter_by(acronym=dept).first_or_404()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
# Récupération des semestres suivant id_dept
|
2022-04-26 15:23:10 +02:00
|
|
|
semestres = models.FormSemestre.query.filter_by(dept_id=dept.id, etat=True)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
# Mise en forme des données
|
2022-05-04 16:28:34 +02:00
|
|
|
data = [d.to_dict_api() for d in semestres]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
2022-04-13 12:39:10 +02:00
|
|
|
@bp.route(
|
|
|
|
"/departements/<string:dept>/formations/<int:formation_id>/referentiel_competences",
|
|
|
|
methods=["GET"],
|
|
|
|
)
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
def referenciel_competences(dept: str, formation_id: int):
|
|
|
|
"""
|
|
|
|
Retourne le référentiel de compétences
|
|
|
|
|
|
|
|
dept : l'acronym d'un département
|
|
|
|
formation_id : l'id d'une formation
|
|
|
|
"""
|
2022-04-26 15:23:10 +02:00
|
|
|
dept = models.Departement.query.filter_by(acronym=dept).first_or_404()
|
2022-03-10 17:43:12 +01:00
|
|
|
|
2022-04-26 15:23:10 +02:00
|
|
|
formation = models.Formation.query.filter_by(
|
|
|
|
id=formation_id, dept_id=dept.id
|
|
|
|
).first_or_404()
|
2022-03-10 17:43:12 +01:00
|
|
|
|
2022-04-26 15:23:10 +02:00
|
|
|
ref_comp = formation.referentiel_competence_id
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-03-10 17:43:12 +01:00
|
|
|
if ref_comp is None:
|
2022-04-13 12:39:10 +02:00
|
|
|
return error_response(
|
|
|
|
204, message="Pas de référenciel de compétences pour cette formation"
|
|
|
|
)
|
2022-03-10 17:43:12 +01:00
|
|
|
else:
|
|
|
|
return jsonify(ref_comp)
|