API: moduleimpl-notes

This commit is contained in:
Emmanuel Viennet 2024-01-23 22:55:00 +01:00
parent 242771c619
commit ece689eb10
4 changed files with 48 additions and 28 deletions

View File

@ -67,7 +67,7 @@ def get_evaluation(evaluation_id: int):
@scodoc @scodoc
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
@as_json @as_json
def evaluations(moduleimpl_id: int): def moduleimpl_evaluations(moduleimpl_id: int):
""" """
Retourne la liste des évaluations d'un moduleimpl Retourne la liste des évaluations d'un moduleimpl
@ -75,14 +75,8 @@ def evaluations(moduleimpl_id: int):
Exemple de résultat : voir /evaluation Exemple de résultat : voir /evaluation
""" """
query = Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id) modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
if g.scodoc_dept: return [evaluation.to_dict_api() for evaluation in modimpl.evaluations]
query = (
query.join(ModuleImpl)
.join(FormSemestre)
.filter_by(dept_id=g.scodoc_dept_id)
)
return [e.to_dict_api() for e in query]
@bp.route("/evaluation/<int:evaluation_id>/notes") @bp.route("/evaluation/<int:evaluation_id>/notes")

View File

@ -8,16 +8,14 @@
ScoDoc 9 API : accès aux moduleimpl ScoDoc 9 API : accès aux moduleimpl
""" """
from flask import g
from flask_json import as_json from flask_json import as_json
from flask_login import login_required from flask_login import login_required
import app
from app.api import api_bp as bp, api_web_bp from app.api import api_bp as bp, api_web_bp
from app.decorators import scodoc, permission_required from app.decorators import scodoc, permission_required
from app.models import ( from app.models import ModuleImpl
FormSemestre, from app.scodoc import sco_liste_notes
ModuleImpl,
)
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@ -62,10 +60,7 @@ def moduleimpl(moduleimpl_id: int):
} }
} }
""" """
query = ModuleImpl.query.filter_by(id=moduleimpl_id) modimpl = ModuleImpl.get_modimpl(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 modimpl.to_dict(convert_objects=True) 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) modimpl = ModuleImpl.get_modimpl(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] return [i.to_dict() for i in modimpl.inscriptions]
@bp.route("/moduleimpl/<int:moduleimpl_id>/notes")
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>/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

View File

@ -264,7 +264,7 @@ def _make_table_notes(
if e.moduleimpl_id != modimpl.id: if e.moduleimpl_id != modimpl.id:
raise ValueError("invalid evaluations list") raise ValueError("invalid evaluations list")
if fmt == "xls": if fmt == "xls" or fmt == "json":
keep_numeric = True # pas de conversion des notes en strings keep_numeric = True # pas de conversion des notes en strings
else: else:
keep_numeric = False keep_numeric = False
@ -279,11 +279,12 @@ def _make_table_notes(
if anonymous_listing: if anonymous_listing:
columns_ids = ["code"] # cols in table columns_ids = ["code"] # cols in table
else: else:
if fmt == "xls" or fmt == "xml": if fmt in {"xls", "xml", "json"}:
columns_ids = ["nom", "prenom"] columns_ids = ["etudid", "nom", "prenom"]
else: else:
columns_ids = ["nomprenom"] 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") columns_ids.append("group")
titles = { titles = {
@ -476,7 +477,7 @@ def _make_table_notes(
if with_emails: if with_emails:
columns_ids += ["email", "emailperso"] columns_ids += ["email", "emailperso"]
# Ajoute lignes en tête et moyennes # 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] rows_head = [row_coefs]
if is_apc: if is_apc:
rows_head.append(row_poids) rows_head.append(row_poids)

View File

@ -1761,7 +1761,9 @@ def evaluation_create(moduleimpl_id):
@permission_required_compat_scodoc7(Permission.ScoView) @permission_required_compat_scodoc7(Permission.ScoView)
@scodoc7func @scodoc7func
def evaluation_listenotes(): 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 evaluation_id = None
moduleimpl_id = None moduleimpl_id = None
vals = scu.get_request_args() vals = scu.get_request_args()