forked from ScoDoc/ScoDoc
API: modif /formsemestre/<int:formsemestre_id>/etudiants[/query]
This commit is contained in:
parent
f0c342fad5
commit
8fa64476b6
@ -251,49 +251,44 @@ def formsemestre_programme(formsemestre_id: int):
|
||||
|
||||
@bp.route(
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants",
|
||||
defaults={"etat": None},
|
||||
defaults={"with_query": False},
|
||||
)
|
||||
@bp.route(
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants/actifs",
|
||||
defaults={"etat": scu.INSCRIT},
|
||||
)
|
||||
@bp.route(
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants/demissionnaires",
|
||||
defaults={"etat": scu.DEMISSION},
|
||||
)
|
||||
@bp.route(
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants/defaillants",
|
||||
defaults={"etat": scu.DEF},
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants/query",
|
||||
defaults={"with_query": True},
|
||||
)
|
||||
@api_web_bp.route(
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants",
|
||||
defaults={"etat": None},
|
||||
defaults={"with_query": False},
|
||||
)
|
||||
@api_web_bp.route(
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants/actifs",
|
||||
defaults={"etat": scu.INSCRIT},
|
||||
)
|
||||
@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},
|
||||
"/formsemestre/<int:formsemestre_id>/etudiants/query",
|
||||
defaults={"with_query": True},
|
||||
)
|
||||
@login_required
|
||||
@scodoc
|
||||
@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."""
|
||||
query = FormSemestre.query.filter_by(id=formsemestre_id)
|
||||
if g.scodoc_dept:
|
||||
query = query.filter_by(dept_id=g.scodoc_dept_id)
|
||||
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
|
||||
if etat is None:
|
||||
inscriptions = formsemestre.inscriptions
|
||||
if with_query:
|
||||
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:
|
||||
inscriptions = [ins for ins in formsemestre.inscriptions if ins.etat == etat]
|
||||
inscriptions = formsemestre.inscriptions
|
||||
|
||||
etuds = [ins.etud.to_dict_short() for ins in inscriptions]
|
||||
# Ajout des groupes de chaque étudiants
|
||||
|
@ -515,22 +515,28 @@ def test_formsemestre_etudiants(api_headers):
|
||||
assert isinstance(group["group_id"], 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
|
||||
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)
|
||||
|
||||
### démissionnaires
|
||||
etuds_dem = GET(
|
||||
f"/formsemestre/{formsemestre_id}/etudiants/demissionnaires",
|
||||
f"/formsemestre/{formsemestre_id}/etudiants/query?etat=D",
|
||||
headers=api_headers,
|
||||
)
|
||||
assert isinstance(etuds_dem, list)
|
||||
|
||||
### défaillants
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user