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-05-03 13:35:17 +02:00
|
|
|
|
from app.api.auth import token_auth, token_permission_required
|
2022-04-27 14:11:06 +02:00
|
|
|
|
from app.scodoc.sco_groups import get_group_members, setGroups, get_partitions_list
|
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-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-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
|
2022-04-27 14:11:06 +02:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
2022-04-27 14:11:06 +02:00
|
|
|
|
# # Récupération de toutes les partitions
|
|
|
|
|
# partitions = models.Partition.query.filter_by(id=formsemestre_id)
|
|
|
|
|
#
|
|
|
|
|
# # Mise en forme des données
|
|
|
|
|
# data = [partition.to_dict() for partition in partitions]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-27 14:11:06 +02:00
|
|
|
|
data = get_partitions_list(formsemestre_id)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/partitions/groups/<int:group_id>", methods=["GET"])
|
|
|
|
|
@bp.route("/partitions/groups/<int:group_id>/etat/<string:etat>", 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-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
|
2022-04-27 14:11:06 +02:00
|
|
|
|
etat : état de l'inscription
|
|
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"etudid": 10,
|
|
|
|
|
"id": 10,
|
|
|
|
|
"dept_id": 1,
|
|
|
|
|
"nom": "BOUTET",
|
|
|
|
|
"prenom": "Marguerite",
|
|
|
|
|
"nom_usuel": "",
|
|
|
|
|
"civilite": "F",
|
|
|
|
|
"date_naissance": null,
|
|
|
|
|
"lieu_naissance": null,
|
|
|
|
|
"dept_naissance": null,
|
|
|
|
|
"nationalite": null,
|
|
|
|
|
"statut": null,
|
|
|
|
|
"boursier": null,
|
|
|
|
|
"photo_filename": null,
|
|
|
|
|
"code_nip": "10",
|
|
|
|
|
"code_ine": "10",
|
|
|
|
|
"scodoc7_id": null,
|
|
|
|
|
"email": "MARGUERITE.BOUTET@example.com",
|
|
|
|
|
"emailperso": null,
|
|
|
|
|
"domicile": null,
|
|
|
|
|
"codepostaldomicile": null,
|
|
|
|
|
"villedomicile": null,
|
|
|
|
|
"paysdomicile": null,
|
|
|
|
|
"telephone": null,
|
|
|
|
|
"telephonemobile": null,
|
|
|
|
|
"fax": null,
|
|
|
|
|
"typeadresse": "domicile",
|
|
|
|
|
"description": null,
|
|
|
|
|
"group_id": 1,
|
|
|
|
|
"etat": "I",
|
|
|
|
|
"civilite_str": "Mme",
|
|
|
|
|
"nom_disp": "BOUTET",
|
|
|
|
|
"nomprenom": "Mme Marguerite BOUTET",
|
|
|
|
|
"ne": "e",
|
|
|
|
|
"email_default": "MARGUERITE.BOUTET@example.com"
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
|
|
|
|
# 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(
|
2022-04-28 16:12:15 +02:00
|
|
|
|
"/partitions/set_groups/partition/<int:partition_id>/groups/<string:groups_id>/delete/<string:groups_to_delete>"
|
|
|
|
|
"/create/<string:groups_to_create>",
|
2022-04-25 15:25:45 +02:00
|
|
|
|
methods=["POST"],
|
2022-03-02 16:45:47 +01:00
|
|
|
|
)
|
2022-05-03 13:35:17 +02:00
|
|
|
|
@token_auth.login_required
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIEtudChangeGroups)
|
2022-04-25 15:25:45 +02:00
|
|
|
|
def set_groups(
|
2022-04-28 16:12:15 +02:00
|
|
|
|
partition_id: int, groups_lists: str, groups_to_delete: str, groups_to_create: str
|
2022-04-25 15:25:45 +02:00
|
|
|
|
):
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
|
|
|
|
Set les groups
|
|
|
|
|
|
|
|
|
|
partition_id : l'id d'une partition
|
2022-04-27 14:11:06 +02:00
|
|
|
|
groups_lists : membres de chaque groupe existant
|
2022-03-02 16:45:47 +01:00
|
|
|
|
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",
|
|
|
|
|
)
|