forked from ScoDoc/ScoDoc
125 lines
3.4 KiB
Python
125 lines
3.4 KiB
Python
##############################################################################
|
||
# ScoDoc
|
||
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
||
# See LICENSE
|
||
##############################################################################
|
||
|
||
"""
|
||
ScoDoc 9 API : accès aux évaluations
|
||
"""
|
||
|
||
from flask import g, jsonify
|
||
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.api.errors import error_response
|
||
from app.models import Evaluation, ModuleImpl, FormSemestre
|
||
from app.scodoc.sco_evaluation_db import do_evaluation_get_all_notes
|
||
from app.scodoc.sco_permissions import Permission
|
||
|
||
|
||
@bp.route("/moduleimpl/<int:moduleimpl_id>/evaluations")
|
||
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>/evaluations")
|
||
@login_required
|
||
@scodoc
|
||
@permission_required(Permission.ScoView)
|
||
def evaluations(moduleimpl_id: int):
|
||
"""
|
||
Retourne la liste des évaluations d'un moduleimpl
|
||
|
||
moduleimpl_id : l'id d'un moduleimpl
|
||
|
||
Exemple de résultat :
|
||
[
|
||
{
|
||
"moduleimpl_id": 1,
|
||
"jour": "20/04/2022",
|
||
"heure_debut": "08h00",
|
||
"description": "eval1",
|
||
"coefficient": 1.0,
|
||
"publish_incomplete": false,
|
||
"numero": 0,
|
||
"id": 1,
|
||
"heure_fin": "09h00",
|
||
"note_max": 20.0,
|
||
"visibulletin": true,
|
||
"evaluation_type": 0,
|
||
"evaluation_id": 1,
|
||
"jouriso": "2022-04-20",
|
||
"duree": "1h",
|
||
"descrheure": " de 08h00 à 09h00",
|
||
"matin": 1,
|
||
"apresmidi": 0
|
||
},
|
||
...
|
||
]
|
||
"""
|
||
query = Evaluation.query.filter_by(id=moduleimpl_id)
|
||
if g.scodoc_dept:
|
||
query = (
|
||
query.join(ModuleImpl)
|
||
.join(FormSemestre)
|
||
.filter_by(dept_id=g.scodoc_dept_id)
|
||
)
|
||
return jsonify([d.to_dict() for d in query])
|
||
|
||
|
||
@bp.route("/evaluation/<int:evaluation_id>/notes")
|
||
@api_web_bp.route("/evaluation/<int:evaluation_id>/notes")
|
||
@login_required
|
||
@scodoc
|
||
@permission_required(Permission.ScoView)
|
||
def evaluation_notes(evaluation_id: int):
|
||
"""
|
||
Retourne la liste des notes à partir de l'id d'une évaluation donnée
|
||
|
||
evaluation_id : l'id d'une évaluation
|
||
|
||
Exemple de résultat :
|
||
{
|
||
"1": {
|
||
"id": 1,
|
||
"etudid": 10,
|
||
"evaluation_id": 1,
|
||
"value": 15.0,
|
||
"comment": "",
|
||
"date": "Wed, 20 Apr 2022 06:49:05 GMT",
|
||
"uid": 2
|
||
},
|
||
"2": {
|
||
"id": 2,
|
||
"etudid": 1,
|
||
"evaluation_id": 1,
|
||
"value": 12.0,
|
||
"comment": "",
|
||
"date": "Wed, 20 Apr 2022 06:49:06 GMT",
|
||
"uid": 2
|
||
},
|
||
...
|
||
}
|
||
"""
|
||
query = Evaluation.query.filter_by(id=evaluation_id)
|
||
if g.scodoc_dept:
|
||
query = (
|
||
query.join(ModuleImpl)
|
||
.join(FormSemestre)
|
||
.filter_by(dept_id=g.scodoc_dept_id)
|
||
)
|
||
|
||
evaluation = query.first_or_404()
|
||
dept = evaluation.moduleimpl.formsemestre.departement
|
||
app.set_sco_dept(dept.acronym)
|
||
|
||
try:
|
||
data = do_evaluation_get_all_notes(evaluation_id)
|
||
except AttributeError: # ???
|
||
return error_response(
|
||
404,
|
||
message="La requête ne peut être traitée en l’état actuel.",
|
||
)
|
||
|
||
return jsonify(data)
|