2022-03-02 16:45:47 +01:00
|
|
|
|
#################################################### Etudiants ########################################################
|
|
|
|
|
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_bulletins_json import make_json_formsemestre_bulletinetud
|
|
|
|
|
from app.scodoc.sco_groups import get_etud_groups
|
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("/etudiants", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_auth.login_required
|
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def etudiants():
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste de tous les étudiants
|
|
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
|
{
|
|
|
|
|
"civilite": "X",
|
|
|
|
|
"code_ine": null,
|
|
|
|
|
"code_nip": null,
|
|
|
|
|
"date_naissance": null,
|
|
|
|
|
"email": null,
|
|
|
|
|
"emailperso": null,
|
|
|
|
|
"etudid": 18,
|
|
|
|
|
"nom": "MOREL",
|
|
|
|
|
"prenom": "JACQUES"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"civilite": "X",
|
|
|
|
|
"code_ine": null,
|
|
|
|
|
"code_nip": null,
|
|
|
|
|
"date_naissance": null,
|
|
|
|
|
"email": null,
|
|
|
|
|
"emailperso": null,
|
|
|
|
|
"etudid": 19,
|
|
|
|
|
"nom": "FOURNIER",
|
|
|
|
|
"prenom": "ANNE"
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
|
"""
|
|
|
|
|
# Récupération de tous les étudiants
|
|
|
|
|
etu = models.Identite.query.all()
|
|
|
|
|
|
|
|
|
|
# Mise en forme des données
|
|
|
|
|
data = [d.to_dict_bul(include_urls=False) for d in etu]
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
# return error_response(501, message="Not implemented")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/etudiants/courant", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_auth.login_required
|
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def etudiants_courant():
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des étudiants courant
|
|
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
|
{
|
|
|
|
|
"civilite": "X",
|
|
|
|
|
"code_ine": null,
|
|
|
|
|
"code_nip": null,
|
|
|
|
|
"date_naissance": null,
|
|
|
|
|
"email": null,
|
|
|
|
|
"emailperso": null,
|
|
|
|
|
"etudid": 18,
|
|
|
|
|
"nom": "MOREL",
|
|
|
|
|
"prenom": "JACQUES"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"civilite": "X",
|
|
|
|
|
"code_ine": null,
|
|
|
|
|
"code_nip": null,
|
|
|
|
|
"date_naissance": null,
|
|
|
|
|
"email": null,
|
|
|
|
|
"emailperso": null,
|
|
|
|
|
"etudid": 19,
|
|
|
|
|
"nom": "FOURNIER",
|
|
|
|
|
"prenom": "ANNE"
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
|
"""
|
|
|
|
|
# Récupération de tous les étudiants
|
|
|
|
|
etus = models.Identite.query.all()
|
|
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
# Récupère uniquement les étudiants courant
|
|
|
|
|
for etu in etus:
|
|
|
|
|
if etu.inscription_courante() is not None:
|
|
|
|
|
data.append(etu.to_dict_bul(include_urls=False))
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
# return error_response(501, message="Not implemented")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/etudiant/etudid/<int:etudid>", methods=["GET"])
|
|
|
|
|
@bp.route("/etudiant/nip/<int:nip>", methods=["GET"])
|
|
|
|
|
@bp.route("/etudiant/ine/<int:ine>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_auth.login_required
|
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def etudiant(etudid: int = None, nip: int = None, ine: int = None):
|
|
|
|
|
"""
|
|
|
|
|
Retourne les informations de l'étudiant correspondant à l'id passé en paramètres.
|
|
|
|
|
|
|
|
|
|
etudid : l'etudid d'un étudiant
|
|
|
|
|
nip : le code nip d'un étudiant
|
|
|
|
|
ine : le code ine d'un étudiant
|
|
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
|
{
|
|
|
|
|
"civilite": "X",
|
|
|
|
|
"code_ine": null,
|
|
|
|
|
"code_nip": null,
|
|
|
|
|
"date_naissance": null,
|
|
|
|
|
"email": null,
|
|
|
|
|
"emailperso": null,
|
|
|
|
|
"etudid": 18,
|
|
|
|
|
"nom": "MOREL",
|
|
|
|
|
"prenom": "JACQUES"
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
etu = []
|
|
|
|
|
|
|
|
|
|
if etudid is not None: # Si route etudid
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = models.Identite.query.filter_by(id=etudid).first()
|
|
|
|
|
|
|
|
|
|
if nip is not None: # Si route nip
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = models.Identite.query.filter_by(code_nip=nip).first()
|
|
|
|
|
|
|
|
|
|
if ine is not None: # Si route ine
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = models.Identite.query.filter_by(code_ine=ine).first()
|
|
|
|
|
|
|
|
|
|
# Mise en forme des données
|
|
|
|
|
data = etu.to_dict_bul(include_urls=False)
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/etudiant/etudid/<int:etudid>/formsemestres")
|
|
|
|
|
@bp.route("/etudiant/nip/<int:nip>/formsemestres")
|
|
|
|
|
@bp.route("/etudiant/ine/<int:ine>/formsemestres")
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_auth.login_required
|
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des semestres qu'un étudiant a suivis
|
|
|
|
|
|
|
|
|
|
etudid : l'etudid d'un étudiant
|
|
|
|
|
nip : le code nip d'un étudiant
|
|
|
|
|
ine : le code ine d'un étudiant
|
|
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"titre": "master machine info",
|
|
|
|
|
"gestion_semestrielle": false,
|
|
|
|
|
"scodoc7_id": null,
|
|
|
|
|
"date_debut": "01/09/2021",
|
|
|
|
|
"bul_bgcolor": null,
|
|
|
|
|
"date_fin": "15/12/2022",
|
|
|
|
|
"resp_can_edit": false,
|
|
|
|
|
"dept_id": 1,
|
|
|
|
|
"etat": true,
|
|
|
|
|
"resp_can_change_ens": false,
|
|
|
|
|
"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,
|
|
|
|
|
"block_moyennes": false,
|
|
|
|
|
"formsemestre_id": 1,
|
|
|
|
|
"titre_num": "master machine info semestre 1",
|
|
|
|
|
"date_debut_iso": "2021-09-01",
|
|
|
|
|
"date_fin_iso": "2022-12-15",
|
|
|
|
|
"responsables": [
|
|
|
|
|
3,
|
|
|
|
|
2
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
|
]
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Récupération de toutes les inscriptions
|
|
|
|
|
inscriptions = models.FormSemestreInscription.query.all()
|
|
|
|
|
|
|
|
|
|
sems = []
|
|
|
|
|
# Filtre les inscriptions contenant l'étudiant
|
|
|
|
|
for sem in inscriptions:
|
|
|
|
|
if etudid is not None: # Si route etudid
|
|
|
|
|
if sem.etudid == etudid:
|
|
|
|
|
sems.append(sem)
|
|
|
|
|
|
|
|
|
|
if nip is not None: # Si route nip
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = models.Identite.query.filter_by(code_nip=nip).first()
|
|
|
|
|
if sem.etudid == etu.etudid:
|
|
|
|
|
sems.append(sem)
|
|
|
|
|
|
|
|
|
|
if ine is not None: # Si route ine
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = models.Identite.query.filter_by(code_ine=ine).firt()
|
|
|
|
|
if sem.etudid == etu.etudid:
|
|
|
|
|
sems.append(sem)
|
|
|
|
|
|
|
|
|
|
# Mise en forme des données
|
2022-03-10 17:43:12 +01:00
|
|
|
|
# data_inscriptions = [d.to_dict() for d in sems]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
formsemestres = []
|
|
|
|
|
|
|
|
|
|
# Filtre les formsemestre contenant les inscriptions de l'étudiant
|
2022-03-10 17:43:12 +01:00
|
|
|
|
for sem in sems:#data_inscriptions:
|
|
|
|
|
res = models.FormSemestre.query.filter_by(id=sem.formsemestre_id).first()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
formsemestres.append(res)
|
|
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
# Mise en forme des données
|
|
|
|
|
for formsem in formsemestres:
|
|
|
|
|
data.append(formsem.to_dict())
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin", methods=["GET"])
|
|
|
|
|
@bp.route("/etudiant/nip/<int:nip>/formsemestre/<int:formsemestre_id>/bulletin", methods=["GET"])
|
|
|
|
|
@bp.route("/etudiant/ine/<int:ine>/formsemestre/<int:formsemestre_id>/bulletin", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_auth.login_required
|
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def etudiant_bulletin_semestre(formsemestre_id, etudid: int = None, nip: int = None, ine: int = None):
|
|
|
|
|
"""
|
|
|
|
|
Retourne le bulletin d'un étudiant en fonction de son id et d'un semestre donné
|
|
|
|
|
|
|
|
|
|
formsemestre_id : l'id d'un formsemestre
|
|
|
|
|
etudid : l'etudid d'un étudiant
|
|
|
|
|
nip : le code nip d'un étudiant
|
|
|
|
|
ine : le code ine d'un étudiant
|
|
|
|
|
"""
|
|
|
|
|
# Fonction utilisée : app.scodoc.sco_bulletins_json.make_json_formsemestre_bulletinetud()
|
|
|
|
|
|
|
|
|
|
etu = None
|
|
|
|
|
if etudid is not None: # Si route etudid
|
|
|
|
|
return make_json_formsemestre_bulletinetud(formsemestre_id, etudid)
|
|
|
|
|
else:
|
|
|
|
|
if nip is not None: # Si route nip
|
|
|
|
|
etu = models.Identite.query.filter_by(code_nip=nip).first()
|
|
|
|
|
|
|
|
|
|
if ine is not None: # Si route ine
|
|
|
|
|
etu = models.Identite.query.filter_by(code_nip=ine).first()
|
|
|
|
|
|
|
|
|
|
if etu is not None: # Si route nip ou ine
|
|
|
|
|
return make_json_formsemestre_bulletinetud(formsemestre_id, etu.etudid)
|
|
|
|
|
|
|
|
|
|
# return error_response(501, message="Not implemented")
|
|
|
|
|
|
|
|
|
|
|
2022-03-04 17:16:08 +01:00
|
|
|
|
@bp.route("/etudiant/etudid/<int:etudid>/semestre/<int:formsemestre_id>/groups", methods=["GET"])
|
|
|
|
|
@bp.route("/etudiant/nip/<int:nip>/semestre/<int:formsemestre_id>/groups", methods=["GET"])
|
|
|
|
|
@bp.route("/etudiant/ine/<int:ine>/semestre/<int:formsemestre_id>/groups", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_auth.login_required
|
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def etudiant_groups(formsemestre_id: int, etudid: int = None, nip: int = None, ine: int = None):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des groupes auxquels appartient l'étudiant dans le semestre indiqué
|
|
|
|
|
|
|
|
|
|
formsemestre_id : l'id d'un formsemestre
|
|
|
|
|
etudid : l'etudid d'un étudiant
|
|
|
|
|
nip : le code nip d'un étudiant
|
|
|
|
|
ine : le code ine d'un étudiant
|
|
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"partition_id": 1,
|
|
|
|
|
"id": 1,
|
|
|
|
|
"formsemestre_id": 1,
|
|
|
|
|
"partition_name": null,
|
|
|
|
|
"numero": 0,
|
|
|
|
|
"bul_show_rank": false,
|
|
|
|
|
"show_in_lists": true,
|
|
|
|
|
"group_id": 1,
|
|
|
|
|
"group_name": null
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"partition_id": 2,
|
|
|
|
|
"id": 2,
|
|
|
|
|
"formsemestre_id": 1,
|
|
|
|
|
"partition_name": "TD",
|
|
|
|
|
"numero": 1,
|
|
|
|
|
"bul_show_rank": false,
|
|
|
|
|
"show_in_lists": true,
|
|
|
|
|
"group_id": 2,
|
|
|
|
|
"group_name": "A"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
"""
|
|
|
|
|
# Fonction utilisée : app.scodoc.sco_groups.get_etud_groups()
|
|
|
|
|
|
|
|
|
|
if etudid is None:
|
|
|
|
|
if nip is not None: # Si route nip
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = models.Identite.query.filter_by(code_nip=nip).first()
|
|
|
|
|
# Récupération de sont etudid
|
|
|
|
|
etudid = etu.etudid
|
|
|
|
|
|
|
|
|
|
if ine is not None: # Si route ine
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = models.Identite.query.filter_by(code_ine=ine).first()
|
|
|
|
|
# Récupération de sont etudid
|
|
|
|
|
etudid = etu.etudid
|
|
|
|
|
|
|
|
|
|
# Récupération du formsemestre
|
|
|
|
|
sem = models.FormSemestre.query.filter_by(id=formsemestre_id).first()
|
|
|
|
|
try:
|
|
|
|
|
# Utilisation de la fonction get_etud_groups
|
|
|
|
|
data = get_etud_groups(etudid, sem.to_dict())
|
|
|
|
|
except ValueError:
|
|
|
|
|
return error_response(409, message="La requête ne peut être traitée en l’état actuel")
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|