diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index 577b2dbc4..eb1a47e98 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -7,6 +7,7 @@ from app.api import bp from app.api.auth import token_auth, token_permission_required from app.models import Departement, FormSemestre, FormSemestreEtape from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json +from app.scodoc.sco_groups import get_etud_groups from app.scodoc.sco_permissions import Permission from app.scodoc.sco_utils import ModuleType @@ -412,3 +413,50 @@ def formsemestre_programme(formsemestre_id: int): "modules": m_list[ModuleType.STANDARD], } ) + + +@bp.route( + "/formsemestre//etudiants/inscrits", + methods=["GET"], + defaults={"etat": "I"}, +) +@bp.route( + "/formsemestre//etudiants/demissionnaires", + methods=["GET"], + defaults={"etat": "D"}, +) +@bp.route( + "/formsemestre//etudiants/defaillants", + methods=["GET"], + defaults={"etat": "DEF"}, +) +@token_auth.login_required +@token_permission_required(Permission.APIView) +def formsemestre_etudiants(formsemestre_id: int, etat: str): + """ + Retourne la liste des étudiants d'un semestre + + formsemestre_id : l'id d'un semestre + """ + # fonction to use : sco_groups.get_etud_groups + + formsemestre = models.FormSemestre.query.filter_by( + id=formsemestre_id + ).first_or_404() + + # Récupération des étudiants du formsemestre + etuds = [etu.to_dict_short() for etu in formsemestre.etuds] + + res = [] + # Trie des étudiants suivant leur état d'inscription voulu + for etu in etuds: + formsemestre_inscription = models.FormSemestreInscription.query.filter_by( + formsemestre_id=formsemestre_id, etudid=etu["id"] + ).first_or_404() + if formsemestre_inscription.etat == etat: + res.append(etu) + # Ajout des groups de chaques étudiants + for etu in res: + etu["groups"] = get_etud_groups(etu["id"], formsemestre_id) + + return jsonify(res) diff --git a/tests/api/test_api_etudiants.py b/tests/api/test_api_etudiants.py index 4e38ecb1e..c0f0470f3 100644 --- a/tests/api/test_api_etudiants.py +++ b/tests/api/test_api_etudiants.py @@ -101,7 +101,7 @@ def test_etudiant(api_headers): ) assert r.status_code == 200 etud = r.json() - assert len(etud) == 25 + assert len(etud) == 26 fields_ok = verify_fields(etud, ETUD_FIELDS) assert fields_ok is True