2022-03-02 16:45:47 +01:00
|
|
|
|
#################################################### Etudiants ########################################################
|
2022-04-20 15:50:02 +02:00
|
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
|
from flask import jsonify
|
|
|
|
|
|
2022-04-26 13:46:09 +02:00
|
|
|
|
import app
|
2022-03-02 16:45:47 +01:00
|
|
|
|
from app import models
|
|
|
|
|
from app.api import bp
|
|
|
|
|
from app.api.errors import error_response
|
2022-04-26 13:46:09 +02:00
|
|
|
|
from app.api.auth import 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
|
2022-04-26 13:46:09 +02:00
|
|
|
|
from app.scodoc import sco_bulletins
|
|
|
|
|
from app.scodoc import sco_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 13:46:09 +02:00
|
|
|
|
etuds = Identite.query.filter(
|
2022-04-26 14:48:43 +02:00
|
|
|
|
Identite.id == FormSemestreInscription.etudid,
|
|
|
|
|
FormSemestreInscription.formsemestre_id == FormSemestre.id,
|
|
|
|
|
FormSemestre.date_debut <= app.db.func.now(),
|
2022-04-26 13:46:09 +02:00
|
|
|
|
FormSemestre.date_fin >= app.db.func.now(),
|
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-26 13:46:09 +02:00
|
|
|
|
data = [etu.to_dict_bul(include_urls=False) for etu in etuds]
|
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):
|
|
|
|
|
"""
|
2022-04-26 13:46:09 +02:00
|
|
|
|
Retourne la liste des semestres qu'un étudiant a suivi, triés par ordre chronologique.
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
"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
|
2022-04-26 13:46:09 +02:00
|
|
|
|
etud = get_etu_from_request(etudid, nip, ine)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-26 13:46:09 +02:00
|
|
|
|
formsemestres = models.FormSemestre.query.filter(
|
|
|
|
|
models.FormSemestreInscription.etudid == etud.id,
|
|
|
|
|
models.FormSemestreInscription.formsemestre_id == models.FormSemestre.id,
|
|
|
|
|
).order_by(models.FormSemestre.date_debut)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-26 13:46:09 +02:00
|
|
|
|
return jsonify([formsemestre.to_dict() for formsemestre in formsemestres])
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
|
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 13:46:09 +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 "
|
2022-04-26 13:46:09 +02:00
|
|
|
|
"Veuillez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide",
|
2022-04-26 14:48:43 +02:00
|
|
|
|
)
|
2022-04-20 15:50:02 +02:00
|
|
|
|
|
2022-04-26 13:46:09 +02:00
|
|
|
|
return sco_bulletins.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"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
"""
|
|
|
|
|
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 "
|
2022-04-26 13:46:09 +02:00
|
|
|
|
"Veuillez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide",
|
2022-04-25 15:25:45 +02:00
|
|
|
|
)
|
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:
|
2022-04-26 13:46:09 +02:00
|
|
|
|
data = sco_groups.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 "
|
2022-04-26 13:46:09 +02:00
|
|
|
|
"Veuillez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide"
|
2022-04-25 15:25:45 +02:00
|
|
|
|
" 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)
|