améliore gestion erreur saisies de notes

This commit is contained in:
Emmanuel Viennet 2021-10-13 15:56:24 +02:00
parent f0d641a31e
commit 1b8186e69b
1 changed files with 11 additions and 7 deletions

View File

@ -45,6 +45,7 @@ from app.scodoc.sco_exceptions import (
AccessDenied, AccessDenied,
InvalidNoteValue, InvalidNoteValue,
NoteProcessError, NoteProcessError,
ScoGenError,
ScoValueError, ScoValueError,
) )
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@ -72,13 +73,16 @@ def convert_note_from_string(
note_max, note_max,
note_min=scu.NOTES_MIN, note_min=scu.NOTES_MIN,
etudid=None, etudid=None,
absents=[], absents=None,
tosuppress=[], tosuppress=None,
invalids=[], invalids=None,
): ):
"""converti une valeur (chaine saisie) vers une note numérique (float) """converti une valeur (chaine saisie) vers une note numérique (float)
Les listes absents, tosuppress et invalids sont modifiées Les listes absents, tosuppress et invalids sont modifiées
""" """
absents = absents or []
tosuppress = tosuppress or []
invalids = invalids or []
invalid = False invalid = False
note_value = None note_value = None
note = note.replace(",", ".") note = note.replace(",", ".")
@ -179,7 +183,6 @@ def do_evaluation_upload_xls():
# Check access # Check access
# (admin, respformation, and responsable_id) # (admin, respformation, and responsable_id)
if not sco_permissions_check.can_edit_notes(authuser, E["moduleimpl_id"]): if not sco_permissions_check.can_edit_notes(authuser, E["moduleimpl_id"]):
# XXX imaginer un redirect + msg erreur
raise AccessDenied("Modification des notes impossible pour %s" % authuser) raise AccessDenied("Modification des notes impossible pour %s" % authuser)
# #
diag, lines = sco_excel.excel_file_to_list(vals["notefile"]) diag, lines = sco_excel.excel_file_to_list(vals["notefile"])
@ -573,12 +576,13 @@ def _notes_add(user, evaluation_id: int, notes: list, comment=None, do_it=True):
except: except:
log("*** exception in _notes_add") log("*** exception in _notes_add")
if do_it: if do_it:
cnx.rollback() # abort
# inval cache # inval cache
sco_cache.invalidate_formsemestre( sco_cache.invalidate_formsemestre(
formsemestre_id=M["formsemestre_id"] formsemestre_id=M["formsemestre_id"]
) # > modif notes (exception) ) # > modif notes (exception)
cnx.rollback() # abort sco_cache.EvaluationCache.delete(evaluation_id)
raise # re-raise exception raise ScoGenError("Erreur enregistrement note: merci de ré-essayer")
if do_it: if do_it:
cnx.commit() cnx.commit()
sco_cache.invalidate_formsemestre( sco_cache.invalidate_formsemestre(
@ -588,7 +592,7 @@ def _notes_add(user, evaluation_id: int, notes: list, comment=None, do_it=True):
return nb_changed, nb_suppress, existing_decisions return nb_changed, nb_suppress, existing_decisions
def saisie_notes_tableur(evaluation_id, group_ids=[]): def saisie_notes_tableur(evaluation_id, group_ids=()):
"""Saisie des notes via un fichier Excel""" """Saisie des notes via un fichier Excel"""
evals = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id}) evals = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id})
if not evals: if not evals: