2022-07-19 22:17:10 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2022-07-19 22:17:10 +02:00
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
ScoDoc 9 API : accès aux évaluations
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
CATEGORY
|
|
|
|
--------
|
|
|
|
Évaluations
|
2022-07-19 22:17:10 +02:00
|
|
|
"""
|
2023-06-03 22:43:04 +02:00
|
|
|
from flask import g, request
|
2023-04-06 16:10:32 +02:00
|
|
|
from flask_json import as_json
|
2023-08-22 17:02:00 +02:00
|
|
|
from flask_login import current_user, login_required
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-04-26 15:26:20 +02:00
|
|
|
import app
|
2023-08-26 16:34:56 +02:00
|
|
|
from app import log, db
|
2022-07-27 16:03:14 +02:00
|
|
|
from app.api import api_bp as bp, api_web_bp
|
2024-07-17 12:03:08 +02:00
|
|
|
from app.api import api_permission_required as permission_required
|
|
|
|
from app.decorators import scodoc
|
2022-07-27 16:03:14 +02:00
|
|
|
from app.models import Evaluation, ModuleImpl, FormSemestre
|
2023-08-25 18:00:49 +02:00
|
|
|
from app.scodoc import sco_evaluation_db, sco_saisie_notes
|
2023-08-22 17:02:00 +02:00
|
|
|
from app.scodoc.sco_exceptions import AccessDenied, ScoValueError
|
2022-03-04 17:16:08 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-08-03 16:05:01 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-11-01 11:19:28 +01:00
|
|
|
@bp.route("/evaluation/<int:evaluation_id>")
|
|
|
|
@api_web_bp.route("/evaluation/<int:evaluation_id>")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2023-08-26 16:34:56 +02:00
|
|
|
def get_evaluation(evaluation_id: int):
|
2022-11-01 11:19:28 +01:00
|
|
|
"""Description d'une évaluation.
|
|
|
|
|
2024-07-24 17:34:30 +02:00
|
|
|
DATA
|
|
|
|
----
|
|
|
|
```json
|
2022-11-01 11:19:28 +01:00
|
|
|
{
|
2024-07-24 17:34:30 +02:00
|
|
|
'coefficient': 1.0,
|
|
|
|
'date_debut': '2016-01-04T08:30:00',
|
|
|
|
'date_fin': '2016-01-04T12:30:00',
|
|
|
|
'description': 'TP Température',
|
|
|
|
'evaluation_type': 0,
|
|
|
|
'id': 15797,
|
|
|
|
'moduleimpl_id': 1234,
|
|
|
|
'note_max': 20.0,
|
|
|
|
'numero': 3,
|
|
|
|
'poids': {
|
|
|
|
'UE1.1': 1.0,
|
|
|
|
'UE1.2': 1.0,
|
|
|
|
'UE1.3': 1.0
|
|
|
|
},
|
|
|
|
'publish_incomplete': False,
|
|
|
|
'visibulletin': True
|
|
|
|
}
|
|
|
|
```
|
2022-11-01 11:19:28 +01:00
|
|
|
"""
|
|
|
|
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)
|
|
|
|
)
|
|
|
|
e = query.first_or_404()
|
2023-04-06 16:10:32 +02:00
|
|
|
return e.to_dict_api()
|
2022-11-01 11:19:28 +01:00
|
|
|
|
|
|
|
|
2022-07-30 08:23:22 +02:00
|
|
|
@bp.route("/moduleimpl/<int:moduleimpl_id>/evaluations")
|
|
|
|
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>/evaluations")
|
2022-07-27 16:03:14 +02:00
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2024-01-23 22:55:00 +01:00
|
|
|
def moduleimpl_evaluations(moduleimpl_id: int):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2024-07-24 17:34:30 +02:00
|
|
|
Retourne la liste des évaluations d'un moduleimpl.
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2024-07-24 17:34:30 +02:00
|
|
|
PARAMS
|
|
|
|
------
|
2022-03-02 16:45:47 +01:00
|
|
|
moduleimpl_id : l'id d'un moduleimpl
|
2022-04-26 15:26:20 +02:00
|
|
|
|
2024-07-24 17:34:30 +02:00
|
|
|
Exemple de résultat : voir `/evaluation`.
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2024-01-23 22:55:00 +01:00
|
|
|
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
|
|
|
|
return [evaluation.to_dict_api() for evaluation in modimpl.evaluations]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-07-27 16:03:14 +02:00
|
|
|
@bp.route("/evaluation/<int:evaluation_id>/notes")
|
|
|
|
@api_web_bp.route("/evaluation/<int:evaluation_id>/notes")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2022-03-02 16:45:47 +01:00
|
|
|
def evaluation_notes(evaluation_id: int):
|
|
|
|
"""
|
2024-07-24 17:34:30 +02:00
|
|
|
Retourne la liste des notes de l'évaluation.
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2024-07-24 17:34:30 +02:00
|
|
|
PARAMS
|
|
|
|
------
|
2023-06-03 22:43:04 +02:00
|
|
|
evaluation_id : l'id de l'évaluation
|
2022-04-26 15:26:20 +02:00
|
|
|
|
|
|
|
Exemple de résultat :
|
2022-04-28 16:12:15 +02:00
|
|
|
{
|
2023-06-03 22:43:04 +02:00
|
|
|
"11": {
|
|
|
|
"etudid": 11,
|
2022-04-28 16:12:15 +02:00
|
|
|
"evaluation_id": 1,
|
|
|
|
"value": 15.0,
|
|
|
|
"comment": "",
|
|
|
|
"date": "Wed, 20 Apr 2022 06:49:05 GMT",
|
|
|
|
"uid": 2
|
|
|
|
},
|
2023-06-03 22:43:04 +02:00
|
|
|
"12": {
|
|
|
|
"etudid": 12,
|
2022-04-28 16:12:15 +02:00
|
|
|
"evaluation_id": 1,
|
|
|
|
"value": 12.0,
|
|
|
|
"comment": "",
|
|
|
|
"date": "Wed, 20 Apr 2022 06:49:06 GMT",
|
|
|
|
"uid": 2
|
|
|
|
},
|
|
|
|
...
|
|
|
|
}
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-07-27 16:03:14 +02:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
|
2023-06-03 22:43:04 +02:00
|
|
|
evaluation = query.first_or_404()
|
|
|
|
dept = evaluation.moduleimpl.formsemestre.departement
|
2022-04-26 15:26:20 +02:00
|
|
|
app.set_sco_dept(dept.acronym)
|
|
|
|
|
2022-08-03 16:05:01 +02:00
|
|
|
notes = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
|
|
|
|
for etudid in notes:
|
|
|
|
# "ABS", "EXC", etc mais laisse les notes sur le barème de l'éval.
|
|
|
|
note = notes[etudid]
|
|
|
|
note["value"] = scu.fmt_note(note["value"], keep_numeric=True)
|
2023-06-03 22:43:04 +02:00
|
|
|
note["note_max"] = evaluation.note_max
|
2022-08-03 16:05:01 +02:00
|
|
|
del note["id"]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2023-06-03 22:43:04 +02:00
|
|
|
# in JS, keys must be string, not integers
|
|
|
|
return {str(etudid): note for etudid, note in notes.items()}
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/evaluation/<int:evaluation_id>/notes/set", methods=["POST"])
|
|
|
|
@api_web_bp.route("/evaluation/<int:evaluation_id>/notes/set", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.EnsView)
|
2023-06-03 22:43:04 +02:00
|
|
|
@as_json
|
2023-12-15 01:07:08 +01:00
|
|
|
def evaluation_set_notes(evaluation_id: int): # evaluation-notes-set
|
2023-06-03 22:43:04 +02:00
|
|
|
"""Écriture de notes dans une évaluation.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
DATA
|
|
|
|
----
|
|
|
|
```json
|
2023-06-03 22:43:04 +02:00
|
|
|
{
|
2023-06-06 22:12:21 +02:00
|
|
|
'notes' : [ [etudid, value], ... ],
|
|
|
|
'comment' : optional string
|
2023-06-03 22:43:04 +02:00
|
|
|
}
|
2024-07-24 17:34:30 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Résultat:
|
|
|
|
|
2023-06-03 22:43:04 +02:00
|
|
|
- nb_changed: nombre de notes changées
|
|
|
|
- nb_suppress: nombre de notes effacées
|
|
|
|
- etudids_with_decision: liste des etudiants dont la note a changé
|
|
|
|
alors qu'ils ont une décision de jury enregistrée.
|
|
|
|
"""
|
|
|
|
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)
|
|
|
|
data = request.get_json(force=True) # may raise 400 Bad Request
|
|
|
|
notes = data.get("notes")
|
|
|
|
if notes is None:
|
|
|
|
return scu.json_error(404, "no notes")
|
|
|
|
if not isinstance(notes, list):
|
|
|
|
return scu.json_error(404, "invalid notes argument (must be a list)")
|
|
|
|
return sco_saisie_notes.save_notes(
|
|
|
|
evaluation, notes, comment=data.get("comment", "")
|
|
|
|
)
|
2023-08-22 17:02:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/moduleimpl/<int:moduleimpl_id>/evaluation/create", methods=["POST"])
|
|
|
|
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>/evaluation/create", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.EnsView) # permission gérée dans la fonction
|
2023-08-22 17:02:00 +02:00
|
|
|
@as_json
|
|
|
|
def evaluation_create(moduleimpl_id: int):
|
|
|
|
"""Création d'une évaluation.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
DATA
|
|
|
|
----
|
2023-08-22 17:02:00 +02:00
|
|
|
{
|
|
|
|
"description" : str,
|
2023-08-25 18:00:49 +02:00
|
|
|
"evaluation_type" : int, // {0,1,2} default 0 (normale)
|
2023-08-22 17:02:00 +02:00
|
|
|
"date_debut" : date_iso, // optionnel
|
2023-08-25 18:00:49 +02:00
|
|
|
"date_fin" : date_iso, // optionnel
|
2023-08-22 17:02:00 +02:00
|
|
|
"note_max" : float, // si non spécifié, 20.0
|
|
|
|
"numero" : int, // ordre de présentation, default tri sur date
|
|
|
|
"visibulletin" : boolean , //default true
|
|
|
|
"publish_incomplete" : boolean , //default false
|
|
|
|
"coefficient" : float, // si non spécifié, 1.0
|
2023-08-26 16:34:56 +02:00
|
|
|
"poids" : { ue_id : poids } // optionnel
|
2023-08-22 17:02:00 +02:00
|
|
|
}
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
Résultat: l'évaluation créée.
|
2023-08-22 17:02:00 +02:00
|
|
|
"""
|
|
|
|
moduleimpl: ModuleImpl = ModuleImpl.query.get_or_404(moduleimpl_id)
|
|
|
|
if not moduleimpl.can_edit_evaluation(current_user):
|
|
|
|
return scu.json_error(403, "opération non autorisée")
|
|
|
|
data = request.get_json(force=True) # may raise 400 Bad Request
|
|
|
|
|
|
|
|
try:
|
|
|
|
evaluation = Evaluation.create(moduleimpl=moduleimpl, **data)
|
|
|
|
except ValueError:
|
|
|
|
return scu.json_error(400, "paramètre incorrect")
|
|
|
|
except ScoValueError as exc:
|
2023-08-25 18:00:49 +02:00
|
|
|
return scu.json_error(
|
|
|
|
400, f"paramètre de type incorrect ({exc.args[0] if exc.args else ''})"
|
|
|
|
)
|
2023-08-22 17:02:00 +02:00
|
|
|
|
|
|
|
db.session.add(evaluation)
|
|
|
|
db.session.commit()
|
2023-08-26 16:34:56 +02:00
|
|
|
# Les poids vers les UEs:
|
|
|
|
poids = data.get("poids")
|
|
|
|
if poids is not None:
|
|
|
|
if not isinstance(poids, dict):
|
|
|
|
log("API error: canceling evaluation creation")
|
|
|
|
db.session.delete(evaluation)
|
|
|
|
db.session.commit()
|
|
|
|
return scu.json_error(
|
|
|
|
400, "paramètre de type incorrect (poids must be a dict)"
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
evaluation.set_ue_poids_dict(data["poids"])
|
|
|
|
except ScoValueError as exc:
|
|
|
|
log("API error: canceling evaluation creation")
|
|
|
|
db.session.delete(evaluation)
|
|
|
|
db.session.commit()
|
|
|
|
return scu.json_error(
|
|
|
|
400,
|
|
|
|
f"erreur enregistrement des poids ({exc.args[0] if exc.args else ''})",
|
|
|
|
)
|
|
|
|
db.session.commit()
|
2023-08-22 17:02:00 +02:00
|
|
|
return evaluation.to_dict_api()
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/evaluation/<int:evaluation_id>/delete", methods=["POST"])
|
|
|
|
@api_web_bp.route("/evaluation/<int:evaluation_id>/delete", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.EnsView) # permission gérée dans la fonction
|
2023-08-22 17:02:00 +02:00
|
|
|
@as_json
|
|
|
|
def evaluation_delete(evaluation_id: int):
|
2023-08-26 16:34:56 +02:00
|
|
|
"""Suppression d'une évaluation.
|
2024-07-24 17:34:30 +02:00
|
|
|
Efface aussi toutes ses notes.
|
2023-08-26 16:34:56 +02:00
|
|
|
"""
|
|
|
|
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)
|
|
|
|
if not evaluation.moduleimpl.can_edit_evaluation(current_user):
|
|
|
|
raise AccessDenied("evaluation_delete")
|
|
|
|
|
|
|
|
sco_saisie_notes.evaluation_suppress_alln(
|
|
|
|
evaluation_id=evaluation_id, dialog_confirmed=True
|
|
|
|
)
|
2023-08-30 09:22:51 +02:00
|
|
|
evaluation.delete()
|
2023-08-26 16:34:56 +02:00
|
|
|
return "ok"
|