diff --git a/app/models/absences.py b/app/models/absences.py index 658a390de..bbff2c5cf 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 bdb5672a8..c5d05e934 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 0ae36bd28..9c8457fac 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 e0733fb77..4f06fb75f 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 0cdd7e930..55b34d38d 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 688744b09..902298ccf 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 df2766d04..fa8dc8d10 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 5418c3ce2..3de5c281f 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 bd01abaec..4901f494d 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 24232164a..ee87f7e72 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 cdc83a042..192ed8d3d 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 2f9308f7e..bf90fe26a 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": '