API: modif /formsemestre/<int:formsemestre_id>/etudiants[/query]

This commit is contained in:
Emmanuel Viennet 2022-08-10 07:16:34 +02:00
parent f0c342fad5
commit 8fa64476b6
2 changed files with 30 additions and 29 deletions

View File

@ -251,49 +251,44 @@ def formsemestre_programme(formsemestre_id: int):
@bp.route( @bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants", "/formsemestre/<int:formsemestre_id>/etudiants",
defaults={"etat": None}, defaults={"with_query": False},
) )
@bp.route( @bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/actifs", "/formsemestre/<int:formsemestre_id>/etudiants/query",
defaults={"etat": scu.INSCRIT}, defaults={"with_query": True},
)
@bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/demissionnaires",
defaults={"etat": scu.DEMISSION},
)
@bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/defaillants",
defaults={"etat": scu.DEF},
) )
@api_web_bp.route( @api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants", "/formsemestre/<int:formsemestre_id>/etudiants",
defaults={"etat": None}, defaults={"with_query": False},
) )
@api_web_bp.route( @api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/actifs", "/formsemestre/<int:formsemestre_id>/etudiants/query",
defaults={"etat": scu.INSCRIT}, defaults={"with_query": True},
)
@api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/demissionnaires",
defaults={"etat": scu.DEMISSION},
)
@api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/defaillants",
defaults={"etat": scu.DEF},
) )
@login_required @login_required
@scodoc @scodoc
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
def formsemestre_etudiants(formsemestre_id: int, etat: str = None): def formsemestre_etudiants(formsemestre_id: int, with_query: bool = False):
"""Etudiants d'un formsemestre.""" """Etudiants d'un formsemestre."""
query = FormSemestre.query.filter_by(id=formsemestre_id) query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept: if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id) query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id) formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
if etat is None: if with_query:
inscriptions = formsemestre.inscriptions etat = request.args.get("etat")
if etat is not None:
etat = {
"actifs": scu.INSCRIT,
"demissionnaires": scu.DEMISSION,
"defaillants": scu.DEF,
}.get(etat, etat)
inscriptions = [
ins for ins in formsemestre.inscriptions if ins.etat == etat
]
else:
inscriptions = formsemestre.inscriptions
else: else:
inscriptions = [ins for ins in formsemestre.inscriptions if ins.etat == etat] inscriptions = formsemestre.inscriptions
etuds = [ins.etud.to_dict_short() for ins in inscriptions] etuds = [ins.etud.to_dict_short() for ins in inscriptions]
# Ajout des groupes de chaque étudiants # Ajout des groupes de chaque étudiants

View File

@ -515,22 +515,28 @@ def test_formsemestre_etudiants(api_headers):
assert isinstance(group["group_id"], int) assert isinstance(group["group_id"], int)
assert group["group_name"] is None or isinstance(group["group_name"], int) assert group["group_name"] is None or isinstance(group["group_name"], int)
## Avec query:
etuds_query = GET(
f"/formsemestre/{formsemestre_id}/etudiants/query", headers=api_headers
)
assert etuds_query == etuds
### actifs ### actifs
etuds_actifs = GET( etuds_actifs = GET(
f"/formsemestre/{formsemestre_id}/etudiants/actifs", headers=api_headers f"/formsemestre/{formsemestre_id}/etudiants/query?etat=I", headers=api_headers
) )
assert isinstance(etuds_actifs, list) assert isinstance(etuds_actifs, list)
### démissionnaires ### démissionnaires
etuds_dem = GET( etuds_dem = GET(
f"/formsemestre/{formsemestre_id}/etudiants/demissionnaires", f"/formsemestre/{formsemestre_id}/etudiants/query?etat=D",
headers=api_headers, headers=api_headers,
) )
assert isinstance(etuds_dem, list) assert isinstance(etuds_dem, list)
### défaillants ### défaillants
etuds_def = GET( etuds_def = GET(
f"/formsemestre/{formsemestre_id}/etudiants/defaillants", headers=api_headers f"/formsemestre/{formsemestre_id}/etudiants/query?etat=DEF", headers=api_headers
) )
assert isinstance(etuds_def, list) assert isinstance(etuds_def, list)