From ece689eb10278a9a41841d9acaf2737b208f2b14 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 23 Jan 2024 22:55:00 +0100 Subject: [PATCH] API: moduleimpl-notes --- app/api/evaluations.py | 12 +++------ app/api/moduleimpl.py | 49 +++++++++++++++++++++++++---------- app/scodoc/sco_liste_notes.py | 11 ++++---- app/views/notes.py | 4 ++- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/app/api/evaluations.py b/app/api/evaluations.py index 76b9be7c1..510ad988d 100644 --- a/app/api/evaluations.py +++ b/app/api/evaluations.py @@ -67,7 +67,7 @@ def get_evaluation(evaluation_id: int): @scodoc @permission_required(Permission.ScoView) @as_json -def evaluations(moduleimpl_id: int): +def moduleimpl_evaluations(moduleimpl_id: int): """ Retourne la liste des évaluations d'un moduleimpl @@ -75,14 +75,8 @@ def evaluations(moduleimpl_id: int): Exemple de résultat : voir /evaluation """ - query = Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id) - if g.scodoc_dept: - query = ( - query.join(ModuleImpl) - .join(FormSemestre) - .filter_by(dept_id=g.scodoc_dept_id) - ) - return [e.to_dict_api() for e in query] + modimpl = ModuleImpl.get_modimpl(moduleimpl_id) + return [evaluation.to_dict_api() for evaluation in modimpl.evaluations] @bp.route("/evaluation//notes") diff --git a/app/api/moduleimpl.py b/app/api/moduleimpl.py index a4843fdf7..4b5db1b0f 100644 --- a/app/api/moduleimpl.py +++ b/app/api/moduleimpl.py @@ -8,16 +8,14 @@ ScoDoc 9 API : accès aux moduleimpl """ -from flask import g from flask_json import as_json from flask_login import login_required +import app from app.api import api_bp as bp, api_web_bp from app.decorators import scodoc, permission_required -from app.models import ( - FormSemestre, - ModuleImpl, -) +from app.models import ModuleImpl +from app.scodoc import sco_liste_notes from app.scodoc.sco_permissions import Permission @@ -62,10 +60,7 @@ def moduleimpl(moduleimpl_id: int): } } """ - 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() + modimpl = ModuleImpl.get_modimpl(moduleimpl_id) return modimpl.to_dict(convert_objects=True) @@ -87,8 +82,36 @@ def moduleimpl_inscriptions(moduleimpl_id: int): ... ] """ - 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() + modimpl = ModuleImpl.get_modimpl(moduleimpl_id) return [i.to_dict() for i in modimpl.inscriptions] + + +@bp.route("/moduleimpl//notes") +@api_web_bp.route("/moduleimpl//notes") +@login_required +@scodoc +@permission_required(Permission.ScoView) +def moduleimpl_notes(moduleimpl_id: int): + """Liste des notes dans ce moduleimpl + Exemple de résultat : + [ + { + "etudid": 17776, // code de l'étudiant + "nom": "DUPONT", + "prenom": "Luz", + "38411": 16.0, // Note dans l'évaluation d'id 38411 + "38410": 15.0, + "moymod": 15.5, // Moyenne INDICATIVE module + "moy_ue_2875": 15.5, // Moyenne vers l'UE 2875 + "moy_ue_2876": 15.5, // Moyenne vers l'UE 2876 + "moy_ue_2877": 15.5 // Moyenne vers l'UE 2877 + }, + ... + ] + """ + modimpl = ModuleImpl.get_modimpl(moduleimpl_id) + app.set_sco_dept(modimpl.formsemestre.departement.acronym) + table, _ = sco_liste_notes.do_evaluation_listenotes( + moduleimpl_id=modimpl.id, fmt="json" + ) + return table diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index 3bf7c0b6a..050ab52f8 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -264,7 +264,7 @@ def _make_table_notes( if e.moduleimpl_id != modimpl.id: raise ValueError("invalid evaluations list") - if fmt == "xls": + if fmt == "xls" or fmt == "json": keep_numeric = True # pas de conversion des notes en strings else: keep_numeric = False @@ -279,11 +279,12 @@ def _make_table_notes( if anonymous_listing: columns_ids = ["code"] # cols in table else: - if fmt == "xls" or fmt == "xml": - columns_ids = ["nom", "prenom"] + if fmt in {"xls", "xml", "json"}: + columns_ids = ["etudid", "nom", "prenom"] else: columns_ids = ["nomprenom"] - if not hide_groups: + if not hide_groups and fmt not in {"xls", "xml", "json"}: + # n'indique pas les groupes en xls, json car notation "humaine" ici columns_ids.append("group") titles = { @@ -476,7 +477,7 @@ def _make_table_notes( if with_emails: columns_ids += ["email", "emailperso"] # Ajoute lignes en tête et moyennes - if len(evaluations) > 0 and fmt != "bordereau": + if len(evaluations) > 0 and fmt != "bordereau" and fmt != "json": rows_head = [row_coefs] if is_apc: rows_head.append(row_poids) diff --git a/app/views/notes.py b/app/views/notes.py index a6e73ac35..43ea7933e 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -1761,7 +1761,9 @@ def evaluation_create(moduleimpl_id): @permission_required_compat_scodoc7(Permission.ScoView) @scodoc7func def evaluation_listenotes(): - """Affichage des notes d'une évaluation""" + """Affichage des notes d'une évaluation. + Si evaluation_id non spécifié, toutes les notes des évaluations de ce modimpl. + """ evaluation_id = None moduleimpl_id = None vals = scu.get_request_args()