From 21fa7112c844282ff48835daac20c53fc9cf9da6 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 27 Nov 2021 18:55:47 +0100 Subject: [PATCH] param checking (exceptions pour utilisateurs) --- app/models/preferences.py | 11 +++++++++-- app/scodoc/sco_inscr_passage.py | 5 +++-- app/scodoc/sco_undo_notes.py | 2 +- app/views/notes.py | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/preferences.py b/app/models/preferences.py index b04ad0da..59c82ec8 100644 --- a/app/models/preferences.py +++ b/app/models/preferences.py @@ -4,6 +4,7 @@ """ from app import db, log from app.scodoc import bonus_sport +from app.scodoc.sco_exceptions import ScoValueError class ScoPreference(db.Model): @@ -94,7 +95,7 @@ class ScoDocSiteConfig(db.Model): """returns bonus func with specified name. If name not specified, return the configured function. None if no bonus function configured. - Raises NameError if func_name not found in module bonus_sport. + Raises ScoValueError if func_name not found in module bonus_sport. """ if func_name is None: c = ScoDocSiteConfig.query.filter_by(name=cls.BONUS_SPORT).first() @@ -103,7 +104,13 @@ class ScoDocSiteConfig(db.Model): func_name = c.value if func_name == "": # pas de bonus défini return None - return getattr(bonus_sport, func_name) + try: + return getattr(bonus_sport, func_name) + except AttributeError: + raise ScoValueError( + f"""Fonction de calcul maison inexistante: {func_name}. + (contacter votre administrateur local).""" + ) @classmethod def get_bonus_sport_func_names(cls): diff --git a/app/scodoc/sco_inscr_passage.py b/app/scodoc/sco_inscr_passage.py index cc917284..2f952cb8 100644 --- a/app/scodoc/sco_inscr_passage.py +++ b/app/scodoc/sco_inscr_passage.py @@ -288,10 +288,11 @@ def formsemestre_inscr_passage( footer = html_sco_header.sco_footer() H = [header] if isinstance(etuds, str): - etuds = etuds.split(",") # vient du form de confirmation + # list de strings, vient du form de confirmation + etuds = [int(x) for x in etuds.split(",") if x] elif isinstance(etuds, int): etuds = [etuds] - etuds = [int(x) for x in etuds] + auth_etuds_by_sem, inscrits, candidats = list_authorized_etuds_by_sem(sem) etuds_set = set(etuds) candidats_set = set(candidats) diff --git a/app/scodoc/sco_undo_notes.py b/app/scodoc/sco_undo_notes.py index f49e75d1..4231f81e 100644 --- a/app/scodoc/sco_undo_notes.py +++ b/app/scodoc/sco_undo_notes.py @@ -176,7 +176,7 @@ def formsemestre_list_saisies_notes(formsemestre_id, format="html"): """Table listant toutes les opérations de saisies de notes, dans toutes les évaluations du semestre. """ - sem = sco_formsemestre.get_formsemestre(formsemestre_id) + sem = sco_formsemestre.get_formsemestre(formsemestre_id, raise_soft_exc=True) r = ndb.SimpleDictFetch( """SELECT i.nom, code_nip, n.*, mod.titre, e.description, e.jour FROM notes_notes n, notes_evaluation e, notes_moduleimpl mi, diff --git a/app/views/notes.py b/app/views/notes.py index 5214977e..6957d682 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -1565,7 +1565,7 @@ def evaluation_delete(evaluation_id): """Form delete evaluation""" El = sco_evaluations.do_evaluation_list(args={"evaluation_id": evaluation_id}) if not El: - raise ValueError("Evalution inexistante ! (%s)" % evaluation_id) + raise ScoValueError("Evalution inexistante ! (%s)" % evaluation_id) E = El[0] M = sco_moduleimpl.moduleimpl_list(moduleimpl_id=E["moduleimpl_id"])[0] Mod = sco_edit_module.module_list(args={"module_id": M["module_id"]})[0]