1
0
forked from ScoDoc/ScoDoc

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
@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/<int:evaluation_id>/notes")

View File

@ -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/<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:
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)

View File

@ -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()