diff --git a/app/models/absences.py b/app/models/absences.py index 658a390d..bbff2c5c 100644 --- a/app/models/absences.py +++ b/app/models/absences.py @@ -4,9 +4,6 @@ """ from app import db -from app.models import APO_CODE_STR_LEN -from app.models import SHORT_STR_LEN -from app.models import CODE_STR_LEN class Absence(db.Model): diff --git a/app/models/entreprises.py b/app/models/entreprises.py index bdb5672a..c5d05e93 100644 --- a/app/models/entreprises.py +++ b/app/models/entreprises.py @@ -4,9 +4,6 @@ """ from app import db -from app.models import APO_CODE_STR_LEN -from app.models import SHORT_STR_LEN -from app.models import CODE_STR_LEN class Entreprise(db.Model): diff --git a/app/models/etudiants.py b/app/models/etudiants.py index 0ae36bd2..9c8457fa 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -8,9 +8,6 @@ from flask import g, url_for from app import db from app import models -from app.models import APO_CODE_STR_LEN -from app.models import SHORT_STR_LEN -from app.models import CODE_STR_LEN class Identite(db.Model): diff --git a/app/models/evaluations.py b/app/models/evaluations.py index e0733fb7..4f06fb75 100644 --- a/app/models/evaluations.py +++ b/app/models/evaluations.py @@ -4,9 +4,6 @@ """ from app import db -from app.models import APO_CODE_STR_LEN -from app.models import SHORT_STR_LEN -from app.models import CODE_STR_LEN from app.models import UniteEns import app.scodoc.notesdb as ndb diff --git a/app/models/events.py b/app/models/events.py index 0cdd7e93..55b34d38 100644 --- a/app/models/events.py +++ b/app/models/events.py @@ -4,9 +4,7 @@ """ from app import db -from app.models import APO_CODE_STR_LEN from app.models import SHORT_STR_LEN -from app.models import CODE_STR_LEN class Scolog(db.Model): diff --git a/app/models/groups.py b/app/models/groups.py index 688744b0..902298cc 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -5,9 +5,7 @@ from typing import Any from app import db -from app.models import APO_CODE_STR_LEN from app.models import SHORT_STR_LEN -from app.models import CODE_STR_LEN from app.models import GROUPNAME_STR_LEN diff --git a/app/models/notes.py b/app/models/notes.py index df2766d0..fa8dc8d1 100644 --- a/app/models/notes.py +++ b/app/models/notes.py @@ -4,7 +4,6 @@ """ from app import db -from app.models import APO_CODE_STR_LEN from app.models import SHORT_STR_LEN from app.models import CODE_STR_LEN diff --git a/app/scodoc/notesdb.py b/app/scodoc/notesdb.py index 5418c3ce..3de5c281 100644 --- a/app/scodoc/notesdb.py +++ b/app/scodoc/notesdb.py @@ -265,8 +265,11 @@ def DBUpdateArgs(cnx, table, vals, where=None, commit=False, convert_empty_to_nu cursor.execute(req, vals) # log('req=%s\n'%req) # log('vals=%s\n'%vals) + except psycopg2.errors.StringDataRightTruncation: + cnx.rollback() + raise ScoValueError("champs de texte trop long !") except: - cnx.commit() # get rid of this transaction + cnx.rollback() # get rid of this transaction log('Exception in DBUpdateArgs:\n\treq="%s"\n\tvals="%s"\n' % (req, vals)) raise # and re-raise exception if commit: diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index bd01abae..4901f494 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -33,6 +33,7 @@ from flask import g, url_for, request from app import db from app import log +from app.models import SHORT_STR_LEN from app.models.formations import Formation from app.models.modules import Module @@ -209,6 +210,7 @@ def formation_edit(formation_id=None, create=False): "size": 12, "title": "Code formation", "explanation": "code interne. Toutes les formations partageant le même code sont compatibles (compensation de semestres, capitalisation d'UE). Laisser vide si vous ne savez pas, ou entrer le code d'une formation existante.", + "validator": lambda val, _: len(val) < SHORT_STR_LEN, }, ), ( diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index 24232164..ee87f7e7 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -32,6 +32,7 @@ import flask from flask import url_for, render_template from flask import g, request from flask_login import current_user +from app.models import APO_CODE_STR_LEN from app.models import Matiere, Module, UniteEns import app.scodoc.notesdb as ndb @@ -397,21 +398,21 @@ def module_delete(module_id=None): return flask.redirect(dest_url) -def do_module_edit(val): +def do_module_edit(vals: dict) -> None: "edit a module" from app.scodoc import sco_edit_formation # check - mod = module_list({"module_id": val["module_id"]})[0] + mod = module_list({"module_id": vals["module_id"]})[0] if module_is_locked(mod["module_id"]): # formation verrouillée: empeche de modifier certains champs: protected_fields = ("coefficient", "ue_id", "matiere_id", "semestre_id") for f in protected_fields: - if f in val: - del val[f] + if f in vals: + del vals[f] # edit cnx = ndb.GetDBConnexion() - _moduleEditor.edit(cnx, val) + _moduleEditor.edit(cnx, vals) Formation.query.get(mod["formation_id"]).invalidate_cached_sems() @@ -604,6 +605,7 @@ def module_edit(module_id=None): "title": "Code Apogée", "size": 25, "explanation": "(optionnel) code élément pédagogique Apogée ou liste de codes ELP séparés par des virgules", + "validator": lambda val, _: len(val) < APO_CODE_STR_LEN, }, ), ( diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index cdc83a04..192ed8d3 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -33,6 +33,7 @@ from flask import url_for, render_template from flask import g, request from flask_login import current_user +from app.models import APO_CODE_STR_LEN from app.models import Formation, UniteEns, ModuleImpl, Module import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu @@ -324,6 +325,7 @@ def ue_edit(ue_id=None, create=False, formation_id=None): "title": "Code Apogée", "size": 25, "explanation": "(optionnel) code élément pédagogique Apogée ou liste de codes ELP séparés par des virgules", + "validator": lambda val, _: len(val) < APO_CODE_STR_LEN, }, ), ( diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index 2f9308f7..bf90fe26 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -33,6 +33,7 @@ from flask_login import current_user from app import db from app.auth.models import User +from app.models import APO_CODE_STR_LEN, SHORT_STR_LEN from app.models import ModuleImpl, Evaluation, EvaluationUEPoids import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu @@ -359,6 +360,7 @@ def do_formsemestre_createwithmodules(edit=False): mf_manual = { "size": 12, "template": '