2022-03-02 16:45:47 +01:00
|
|
|
|
############################################### Partitions ############################################################
|
|
|
|
|
from flask import jsonify
|
|
|
|
|
|
|
|
|
|
from app import models
|
|
|
|
|
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-04-25 15:25:45 +02:00
|
|
|
|
from app.api.auth import token_permission_required
|
2022-03-02 16:45:47 +01:00
|
|
|
|
from app.scodoc.sco_groups import get_group_members, setGroups
|
2022-03-04 17:16:08 +01:00
|
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/partitions/<int:formsemestre_id>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def partition(formsemestre_id: int):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste de toutes les partitions d'un formsemestre
|
|
|
|
|
|
|
|
|
|
formsemestre_id : l'id d'un formsemestre
|
|
|
|
|
"""
|
|
|
|
|
# Récupération de toutes les partitions
|
2022-04-26 17:12:30 +02:00
|
|
|
|
partitions = models.Partition.query.filter_by(id=formsemestre_id)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
# Mise en forme des données
|
|
|
|
|
data = [d.to_dict() for d in partitions]
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
# return error_response(501, message="Not implemented")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/partitions/groups/<int:group_id>", methods=["GET"])
|
|
|
|
|
@bp.route("/partitions/groups/<int:group_id>/etat/<string:etat>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
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 :
|
|
|
|
|
"""
|
|
|
|
|
# Fonction utilisée : app.scodoc.sco_groups.get_group_members()
|
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
if etat is None:
|
|
|
|
|
data = get_group_members(group_id)
|
|
|
|
|
else:
|
|
|
|
|
data = get_group_members(group_id, etat)
|
|
|
|
|
|
|
|
|
|
if len(data) == 0:
|
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel. \n"
|
|
|
|
|
"Aucun groupe ne correspond au 'group_id' renseigné",
|
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
|
|
|
|
"/partitions/set_groups?partition_id=<int:partition_id>&groups_lists=<int:groups_lists>&"
|
2022-04-25 15:25:45 +02:00
|
|
|
|
"groups_to_create=<int:groups_to_create>&groups_to_delete=<int:groups_to_delete>",
|
|
|
|
|
methods=["POST"],
|
2022-03-02 16:45:47 +01:00
|
|
|
|
)
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIEtudChangeGroups)
|
2022-04-25 15:25:45 +02:00
|
|
|
|
def set_groups(
|
|
|
|
|
partition_id: int, groups_lists: int, groups_to_delete: int, groups_to_create: int
|
|
|
|
|
):
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
|
|
|
|
Set les groups
|
|
|
|
|
|
|
|
|
|
partition_id : l'id d'une partition
|
|
|
|
|
groups_lists :
|
|
|
|
|
groups_ti_delete : les groupes à supprimer
|
|
|
|
|
groups_to_create : les groupes à créer
|
|
|
|
|
"""
|
|
|
|
|
# Fonction utilisée : app.scodoc.sco_groups.setGroups()
|
|
|
|
|
try:
|
|
|
|
|
# Utilisation de la fonction setGroups
|
|
|
|
|
setGroups(partition_id, groups_lists, groups_to_create, groups_to_delete)
|
|
|
|
|
return error_response(200, message="Groups set")
|
|
|
|
|
except ValueError:
|
2022-04-25 15:25:45 +02:00
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel. \n"
|
|
|
|
|
"Veillez vérifier la conformité des éléments passé en paramètres",
|
|
|
|
|
)
|