From 149522bcd3be74440fec0a2cea72804c60b23ebd Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 23 Jul 2022 09:07:53 +0200 Subject: [PATCH] API: Modification structure partitions/groupes --- app/api/partitions.py | 27 +++++++++++++++++++++++---- app/models/groups.py | 6 +++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/api/partitions.py b/app/api/partitions.py index c8c2133b8..822fb7645 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -24,7 +24,8 @@ from app.scodoc import sco_utils as scu @bp.route("/partition/", methods=["GET"]) @permission_required_api(Permission.ScoView, Permission.APIView) def partition_info(partition_id: int): - """ + """Info sur une partition. + Exemple de résultat : ``` { @@ -49,15 +50,33 @@ def partition_info(partition_id: int): @bp.route("/formsemestre//partitions", methods=["GET"]) @permission_required_api(Permission.ScoView, Permission.APIView) def formsemestre_partitions(formsemestre_id: int): - """ - Retourne la liste de toutes les partitions d'un formsemestre + """Liste de toutes les partitions d'un formsemestre formsemestre_id : l'id d'un formsemestre + { + partition_id : { + "bul_show_rank": False, + "formsemestre_id": 1063, + "groups" : + group_id : { + "id" : 12, + "name" : "A", + "partition_id" : partition_id, + } + }, + ... + } + """ formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id) + partitions = sorted(formsemestre.partitions, key=lambda p: p.numero) return jsonify( - [partition.to_dict(with_groups=True) for partition in formsemestre.partitions] + { + partition.id: partition.to_dict(with_groups=True) + for partition in partitions + if partition.partition_name is not None + } ) diff --git a/app/models/groups.py b/app/models/groups.py index 6ffcf3cc4..d6682d5a0 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -90,7 +90,11 @@ class Partition(db.Model): d.pop("formsemestre", None) if with_groups: - d["groups"] = [group.to_dict(with_partition=False) for group in self.groups] + groups = sorted(self.groups, key=lambda g: g.group_name) + # un dict et non plus une liste, pour JSON + d["groups"] = { + group.id: group.to_dict(with_partition=False) for group in groups + } return d