From 366bd0bea7e7b36e5f200876c2bc19bb65912b00 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 20 Sep 2023 12:45:24 +0200 Subject: [PATCH] API: ajout moduleimpl-inscriptions --- app/api/assiduites.py | 1 + app/api/moduleimpl.py | 25 +++++++++++++++++++++++++ app/models/assiduites.py | 2 +- app/models/moduleimpls.py | 8 ++++++++ sco_version.py | 2 +- tests/unit/test_assiduites.py | 2 +- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/api/assiduites.py b/app/api/assiduites.py index dd2be3c9c..295fd2ab2 100644 --- a/app/api/assiduites.py +++ b/app/api/assiduites.py @@ -559,6 +559,7 @@ def _create_singular( data: dict, etud: Identite, ) -> tuple[int, object]: + """TODO: documenter""" errors: list[str] = [] # -- vérifications de l'objet json -- diff --git a/app/api/moduleimpl.py b/app/api/moduleimpl.py index b8e87c052..556f3d077 100644 --- a/app/api/moduleimpl.py +++ b/app/api/moduleimpl.py @@ -67,3 +67,28 @@ def moduleimpl(moduleimpl_id: int): query = query.join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id) modimpl: ModuleImpl = query.first_or_404() return modimpl.to_dict(convert_objects=True) + + +@bp.route("/moduleimpl//inscriptions") +@api_web_bp.route("/moduleimpl//inscriptions") +@login_required +@scodoc +@permission_required(Permission.ScoView) +@as_json +def moduleimpl_inscriptions(moduleimpl_id: int): + """Liste des inscriptions à ce moduleimpl + Exemple de résultat : + [ + { + "id": 1, + "etudid": 666, + "moduleimpl_id": 1234, + }, + ... + ] + """ + query = ModuleImpl.query.filter_by(id=moduleimpl_id) + if g.scodoc_dept: + query = query.join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id) + modimpl: ModuleImpl = query.first_or_404() + return [i.to_dict() for i in modimpl.inscriptions] diff --git a/app/models/assiduites.py b/app/models/assiduites.py index ca787e980..3fc6d8787 100644 --- a/app/models/assiduites.py +++ b/app/models/assiduites.py @@ -156,7 +156,7 @@ class Assiduite(db.Model): external_data=external_data, ) else: - raise ScoValueError("L'étudiant n'est pas inscrit au moduleimpl") + raise ScoValueError("L'étudiant n'est pas inscrit au module") else: nouv_assiduite = Assiduite( date_debut=date_debut, diff --git a/app/models/moduleimpls.py b/app/models/moduleimpls.py index a44a4b5fc..27df7f48e 100644 --- a/app/models/moduleimpls.py +++ b/app/models/moduleimpls.py @@ -219,6 +219,14 @@ class ModuleImplInscription(db.Model): backref=db.backref("inscriptions", cascade="all, delete-orphan"), ) + def to_dict(self) -> dict: + "dict repr." + return { + "id": self.id, + "etudid": self.etudid, + "moduleimpl_id": self.moduleimpl_id, + } + @classmethod def etud_modimpls_in_ue( cls, formsemestre_id: int, etudid: int, ue_id: int diff --git a/sco_version.py b/sco_version.py index 56bc64b5b..e2f9b7bdc 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.31" +SCOVERSION = "9.6.32" SCONAME = "ScoDoc" diff --git a/tests/unit/test_assiduites.py b/tests/unit/test_assiduites.py index 46016f267..1fceaa0d8 100644 --- a/tests/unit/test_assiduites.py +++ b/tests/unit/test_assiduites.py @@ -889,7 +889,7 @@ def ajouter_assiduites( test_assiduite["desc"], ) except ScoValueError as excp: - assert excp.args[0] == "L'étudiant n'est pas inscrit au moduleimpl" + assert excp.args[0] == "L'étudiant n'est pas inscrit au module" def verifier_comptage_et_filtrage_assiduites(