forked from ScoDoc/ScoDoc
95 lines
2.7 KiB
Python
95 lines
2.7 KiB
Python
##############################################################################
|
|
# ScoDoc
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
# See LICENSE
|
|
##############################################################################
|
|
|
|
"""
|
|
ScoDoc 9 API : partitions
|
|
"""
|
|
from flask import jsonify
|
|
|
|
from app.api import bp
|
|
|
|
from app.api.errors import error_response
|
|
from app.api.auth import token_auth, token_permission_required
|
|
from app.models import FormSemestre, FormSemestreInscription, Identite
|
|
from app.models import GroupDescr, Partition
|
|
from app.models.groups import group_membership
|
|
from app.scodoc.sco_permissions import Permission
|
|
|
|
|
|
@bp.route("/partitions/<int:formsemestre_id>", methods=["GET"])
|
|
@token_auth.login_required
|
|
@token_permission_required(Permission.APIView)
|
|
def partition(formsemestre_id: int):
|
|
"""
|
|
Retourne la liste de toutes les partitions d'un formsemestre
|
|
|
|
formsemestre_id : l'id d'un formsemestre
|
|
|
|
Exemple de résultat :
|
|
[
|
|
{
|
|
"partition_id": 2,
|
|
"id": 2,
|
|
"formsemestre_id": 1,
|
|
"partition_name": "TD",
|
|
"numero": 1,
|
|
"bul_show_rank": false,
|
|
"show_in_lists": true
|
|
},
|
|
{
|
|
"partition_id": 1,
|
|
"id": 1,
|
|
"formsemestre_id": 1,
|
|
"partition_name": null,
|
|
"numero": 0,
|
|
"bul_show_rank": false,
|
|
"show_in_lists": true
|
|
}
|
|
]
|
|
"""
|
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
|
return jsonify([partition.to_dict() for partition in formsemestre.partitions])
|
|
|
|
|
|
@bp.route("/partition/group/<int:group_id>", methods=["GET"])
|
|
@bp.route("/partition/group/<int:group_id>/etat/<string:etat>", methods=["GET"])
|
|
@token_auth.login_required
|
|
@token_permission_required(Permission.APIView)
|
|
def etud_in_group(group_id: int, etat=None):
|
|
"""
|
|
Retourne la liste des étudiants dans un groupe
|
|
|
|
group_id : l'id d'un groupe
|
|
etat : état de l'inscription
|
|
|
|
Exemple de résultat :
|
|
[
|
|
{
|
|
'civilite': 'M',
|
|
'id': 123456,
|
|
'ine': None,
|
|
'nip': '987654321',
|
|
'nom': 'MARTIN',
|
|
'nom_usuel': null,
|
|
'prenom': 'JEAN'}
|
|
},
|
|
...
|
|
]
|
|
"""
|
|
# Fonction utilisée : app.scodoc.sco_groups.get_group_members()
|
|
group = GroupDescr.query.get_or_404(group_id)
|
|
if etat is None:
|
|
query = group.etuds
|
|
else:
|
|
query = (
|
|
Identite.query.join(FormSemestreInscription)
|
|
.filter_by(formsemestre_id=group.partition.formsemestre_id, etat=etat)
|
|
.join(group_membership)
|
|
.filter_by(group_id=group_id)
|
|
)
|
|
|
|
return jsonify([etud.to_dict_short() for etud in query])
|