2022-07-19 22:17:10 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
|
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
ScoDoc 9 API : partitions
|
|
|
|
"""
|
2022-07-20 08:19:24 +02:00
|
|
|
from flask import abort, jsonify, request
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
from app.api import bp
|
2022-04-25 15:25:45 +02:00
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
from app.api.errors import error_response
|
2022-05-03 13:35:17 +02:00
|
|
|
from app.api.auth import token_auth, token_permission_required
|
2022-07-19 22:17:10 +02:00
|
|
|
from app.models import FormSemestre, FormSemestreInscription, Identite
|
|
|
|
from app.models import GroupDescr, Partition
|
|
|
|
from app.models.groups import group_membership
|
2022-03-04 17:16:08 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-07-20 08:19:24 +02:00
|
|
|
from app.scodoc import sco_utils as scu
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-07-20 08:19:24 +02:00
|
|
|
@bp.route("/partition/<int:partition_id>", methods=["GET"])
|
2022-05-03 13:35:17 +02:00
|
|
|
@token_auth.login_required
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-07-20 08:19:24 +02:00
|
|
|
def partition_info(partition_id: int):
|
|
|
|
"""
|
|
|
|
Exemple de résultat :
|
|
|
|
```
|
|
|
|
{
|
|
|
|
'bul_show_rank': False,
|
|
|
|
'formsemestre_id': 39,
|
|
|
|
'groups': [
|
|
|
|
{'id': 268, 'name': 'A', 'partition_id': 100},
|
|
|
|
{'id': 269, 'name': 'B', 'partition_id': 100}
|
|
|
|
],
|
|
|
|
'groups_editable': True,
|
|
|
|
'id': 100,
|
|
|
|
'numero': 100,
|
|
|
|
'partition_name': 'TD',
|
|
|
|
'show_in_lists': True
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"""
|
|
|
|
partition = Partition.query.get_or_404(partition_id)
|
|
|
|
return jsonify(partition.to_dict(with_groups=True))
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/formsemestre/<int:formsemestre_id>/partitions", methods=["GET"])
|
|
|
|
@token_auth.login_required
|
|
|
|
@token_permission_required(Permission.APIView)
|
|
|
|
def formsemestre_partitions(formsemestre_id: int):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
Retourne la liste de toutes les partitions d'un formsemestre
|
|
|
|
|
|
|
|
formsemestre_id : l'id d'un formsemestre
|
2022-04-27 14:11:06 +02:00
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-07-19 22:17:10 +02:00
|
|
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
2022-07-20 08:19:24 +02:00
|
|
|
return jsonify(
|
|
|
|
[partition.to_dict(with_groups=True) for partition in formsemestre.partitions]
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-07-20 08:19:24 +02:00
|
|
|
@bp.route("/group/<int:group_id>/etudiants", methods=["GET"])
|
2022-05-03 13:35:17 +02:00
|
|
|
@token_auth.login_required
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-07-20 08:19:24 +02:00
|
|
|
def etud_in_group(group_id: int):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
Retourne la liste des étudiants dans un groupe
|
|
|
|
|
|
|
|
group_id : l'id d'un groupe
|
2022-04-27 14:11:06 +02:00
|
|
|
|
|
|
|
Exemple de résultat :
|
2022-07-19 22:17:10 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
'civilite': 'M',
|
|
|
|
'id': 123456,
|
|
|
|
'ine': None,
|
|
|
|
'nip': '987654321',
|
|
|
|
'nom': 'MARTIN',
|
|
|
|
'nom_usuel': null,
|
|
|
|
'prenom': 'JEAN'}
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-07-19 22:17:10 +02:00
|
|
|
group = GroupDescr.query.get_or_404(group_id)
|
2022-07-20 08:19:24 +02:00
|
|
|
return jsonify([etud.to_dict_short() for etud in group.etuds])
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/group/<int:group_id>/etudiants/query", methods=["GET"])
|
|
|
|
def etud_in_group_query(group_id: int):
|
|
|
|
"""Etudiants du groupe, filtrés par état"""
|
|
|
|
etat = request.get("etat", "")
|
|
|
|
if etat not in {scu.INSCRIT, scu.DEMISSION, scu.DEF}:
|
|
|
|
abort(404, "etat invalid")
|
|
|
|
group = GroupDescr.query.get_or_404(group_id)
|
|
|
|
query = (
|
|
|
|
Identite.query.join(FormSemestreInscription)
|
|
|
|
.filter_by(formsemestre_id=group.partition.formsemestre_id, etat=etat)
|
|
|
|
.join(group_membership)
|
|
|
|
.filter_by(group_id=group_id)
|
|
|
|
)
|
2022-07-19 22:17:10 +02:00
|
|
|
|
|
|
|
return jsonify([etud.to_dict_short() for etud in query])
|