2022-03-02 16:45:47 +01:00
|
|
|
|
############################################### Partitions ############################################################
|
|
|
|
|
from flask import jsonify
|
|
|
|
|
|
|
|
|
|
from app import models
|
|
|
|
|
from app.api import bp
|
|
|
|
|
from app.api.auth import token_auth
|
|
|
|
|
from app.api.errors import error_response
|
2022-03-04 17:16:08 +01:00
|
|
|
|
from app.decorators import permission_required
|
2022-04-14 14:56:36 +02:00
|
|
|
|
from app.api.auth import token_auth, 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_auth.login_required
|
|
|
|
|
@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
|
|
|
|
|
partitions = models.Partition.query.filter_by(id=formsemestre_id).all()
|
|
|
|
|
|
|
|
|
|
# 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/formsemestre/<int:formsemestre_id>/groups/group_ids?with_codes=&all_groups=&etat=",
|
|
|
|
|
# methods=["GET"],
|
|
|
|
|
# )
|
|
|
|
|
@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_auth.login_required
|
|
|
|
|
@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()
|
|
|
|
|
|
|
|
|
|
if etat is None: # Si l'état n'est pas renseigné
|
|
|
|
|
try:
|
|
|
|
|
# Utilisation de la fonction get_group_members
|
|
|
|
|
data = get_group_members(group_id)
|
|
|
|
|
except ValueError:
|
|
|
|
|
return error_response(409, message="La requête ne peut être traitée en l’état actuel")
|
|
|
|
|
else: # Si l'état est renseigné
|
|
|
|
|
try:
|
|
|
|
|
# Utilisation de la fonction get_group_members
|
|
|
|
|
data = get_group_members(group_id, etat)
|
|
|
|
|
except ValueError:
|
|
|
|
|
return error_response(409, message="La requête ne peut être traitée en l’état actuel")
|
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
|
|
|
|
"/partitions/set_groups?partition_id=<int:partition_id>&groups_lists=<int:groups_lists>&"
|
|
|
|
|
"groups_to_create=<int:groups_to_create>&groups_to_delete=<int:groups_to_delete>", methods=["POST"],
|
|
|
|
|
)
|
|
|
|
|
@token_auth.login_required
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIEtudChangeGroups)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def set_groups(partition_id: int, groups_lists: int, groups_to_delete: int, groups_to_create: int):
|
|
|
|
|
"""
|
|
|
|
|
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:
|
|
|
|
|
return error_response(409, message="La requête ne peut être traitée en l’état actuel")
|