2022-03-02 16:45:47 +01:00
|
|
|
|
#################################################### Etudiants ########################################################
|
2022-04-20 15:50:02 +02:00
|
|
|
|
import app
|
|
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
|
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-04-22 16:22:10 +02:00
|
|
|
|
from app.api.tools import get_etu_from_request
|
2022-04-26 14:48:43 +02:00
|
|
|
|
from app.models import FormSemestreInscription, FormSemestre, Identite
|
|
|
|
|
from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json
|
2022-03-02 16:45:47 +01:00
|
|
|
|
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/courant", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@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
|
2022-04-26 14:48:43 +02:00
|
|
|
|
etus = Identite.query.filter(
|
|
|
|
|
Identite.id == FormSemestreInscription.etudid,
|
|
|
|
|
FormSemestreInscription.formsemestre_id == FormSemestre.id,
|
|
|
|
|
FormSemestre.date_debut <= app.db.func.now(),
|
|
|
|
|
FormSemestre.date_fin >= app.db.func.now())
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-26 14:48:43 +02:00
|
|
|
|
data = [etu.to_dict_bul(include_urls=False) for etu in etus]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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_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"
|
|
|
|
|
}
|
|
|
|
|
"""
|
2022-04-22 16:22:10 +02:00
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = get_etu_from_request(etudid, nip, ine)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
# 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_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
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
|
]
|
|
|
|
|
"""
|
2022-04-22 16:22:10 +02:00
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
etu = get_etu_from_request(etudid, nip, ine)
|
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
# Récupération de toutes les inscriptions de l'étudiant
|
|
|
|
|
formsemestres_inscriptions = models.FormSemestreInscription.query.filter_by(
|
|
|
|
|
etud=etu
|
|
|
|
|
).all()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
formsemestres = []
|
2022-04-25 15:25:45 +02:00
|
|
|
|
# Récupération des formsemestres contenant les inscriptions de l'étudiant
|
|
|
|
|
for formsemestre_inscription in formsemestres_inscriptions:
|
|
|
|
|
res = models.FormSemestre.query.filter_by(
|
|
|
|
|
id=formsemestre_inscription.formsemestre_id
|
2022-04-26 14:48:43 +02:00
|
|
|
|
).first_or_404()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
formsemestres.append(res)
|
|
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
# Mise en forme des données
|
2022-04-25 15:25:45 +02:00
|
|
|
|
for formsemestre in formsemestres:
|
|
|
|
|
data.append(formsemestre.to_dict())
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
@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_permission_required(Permission.APIView)
|
2022-04-25 15:25:45 +02:00
|
|
|
|
def etudiant_bulletin_semestre(
|
|
|
|
|
formsemestre_id, etudid: int = None, nip: int = None, ine: int = None
|
|
|
|
|
):
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
|
"""
|
2022-04-25 15:25:45 +02:00
|
|
|
|
# Fonction utilisée : app.scodoc.sco_bulletins_json.make_json_formsemestre_bulletinetud()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-26 14:48:43 +02:00
|
|
|
|
formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first_or_404()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-26 14:48:43 +02:00
|
|
|
|
dept = models.Departement.query.filter_by(id=formsemestre.dept_id).first_or_404()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-20 15:50:02 +02:00
|
|
|
|
app.set_sco_dept(dept.acronym)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-26 14:48:43 +02:00
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
try:
|
|
|
|
|
etu = get_etu_from_request(etudid, nip, ine)
|
|
|
|
|
except AttributeError:
|
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel.\n "
|
|
|
|
|
"Veilliez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide",
|
|
|
|
|
)
|
2022-04-20 15:50:02 +02:00
|
|
|
|
|
2022-04-26 14:48:43 +02:00
|
|
|
|
return get_formsemestre_bulletin_etud_json(formsemestre, etu)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
|
2022-04-25 15:25:45 +02: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_permission_required(Permission.APIView)
|
2022-04-25 15:25:45 +02:00
|
|
|
|
def etudiant_groups(
|
|
|
|
|
formsemestre_id: int, etudid: int = None, nip: int = None, ine: int = None
|
|
|
|
|
):
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
|
|
|
|
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:
|
2022-04-22 16:22:10 +02:00
|
|
|
|
# Récupération de l'étudiant
|
2022-04-25 15:25:45 +02:00
|
|
|
|
try:
|
|
|
|
|
etu = get_etu_from_request(etudid, nip, ine)
|
|
|
|
|
etudid = etu.etudid
|
|
|
|
|
except AttributeError:
|
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel.\n "
|
|
|
|
|
"Veilliez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide",
|
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
# Récupération du formsemestre
|
2022-04-26 14:48:43 +02:00
|
|
|
|
sem = models.FormSemestre.query.filter_by(id=formsemestre_id).first_or_404()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
try:
|
|
|
|
|
# Utilisation de la fonction get_etud_groups
|
2022-04-15 15:57:44 +02:00
|
|
|
|
data = get_etud_groups(etudid, sem.id)
|
2022-04-25 15:25:45 +02:00
|
|
|
|
except AttributeError:
|
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel.\n "
|
|
|
|
|
"Veilliez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide"
|
|
|
|
|
" et le formsemestre_id sont valides",
|
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-22 16:22:10 +02:00
|
|
|
|
return jsonify(data)
|