1
0
forked from ScoDoc/ScoDoc

Messages erreurs quand saisie champs trop longs

This commit is contained in:
Emmanuel Viennet 2021-12-29 19:30:49 +01:00
parent 9cd31e66f0
commit 9b5b4777e2
15 changed files with 28 additions and 25 deletions

View File

@ -4,9 +4,6 @@
""" """
from app import db 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): class Absence(db.Model):

View File

@ -4,9 +4,6 @@
""" """
from app import db 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): class Entreprise(db.Model):

View File

@ -8,9 +8,6 @@ from flask import g, url_for
from app import db from app import db
from app import models 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): class Identite(db.Model):

View File

@ -4,9 +4,6 @@
""" """
from app import db 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 from app.models import UniteEns
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb

View File

@ -4,9 +4,7 @@
""" """
from app import db from app import db
from app.models import APO_CODE_STR_LEN
from app.models import SHORT_STR_LEN from app.models import SHORT_STR_LEN
from app.models import CODE_STR_LEN
class Scolog(db.Model): class Scolog(db.Model):

View File

@ -5,9 +5,7 @@
from typing import Any from typing import Any
from app import db from app import db
from app.models import APO_CODE_STR_LEN
from app.models import SHORT_STR_LEN from app.models import SHORT_STR_LEN
from app.models import CODE_STR_LEN
from app.models import GROUPNAME_STR_LEN from app.models import GROUPNAME_STR_LEN

View File

@ -4,7 +4,6 @@
""" """
from app import db from app import db
from app.models import APO_CODE_STR_LEN
from app.models import SHORT_STR_LEN from app.models import SHORT_STR_LEN
from app.models import CODE_STR_LEN from app.models import CODE_STR_LEN

View File

@ -265,8 +265,11 @@ def DBUpdateArgs(cnx, table, vals, where=None, commit=False, convert_empty_to_nu
cursor.execute(req, vals) cursor.execute(req, vals)
# log('req=%s\n'%req) # log('req=%s\n'%req)
# log('vals=%s\n'%vals) # log('vals=%s\n'%vals)
except psycopg2.errors.StringDataRightTruncation:
cnx.rollback()
raise ScoValueError("champs de texte trop long !")
except: 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)) log('Exception in DBUpdateArgs:\n\treq="%s"\n\tvals="%s"\n' % (req, vals))
raise # and re-raise exception raise # and re-raise exception
if commit: if commit:

View File

@ -33,6 +33,7 @@ from flask import g, url_for, request
from app import db from app import db
from app import log from app import log
from app.models import SHORT_STR_LEN
from app.models.formations import Formation from app.models.formations import Formation
from app.models.modules import Module from app.models.modules import Module
@ -209,6 +210,7 @@ def formation_edit(formation_id=None, create=False):
"size": 12, "size": 12,
"title": "Code formation", "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.", "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,
}, },
), ),
( (

View File

@ -32,6 +32,7 @@ import flask
from flask import url_for, render_template from flask import url_for, render_template
from flask import g, request from flask import g, request
from flask_login import current_user from flask_login import current_user
from app.models import APO_CODE_STR_LEN
from app.models import Matiere, Module, UniteEns from app.models import Matiere, Module, UniteEns
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
@ -397,21 +398,21 @@ def module_delete(module_id=None):
return flask.redirect(dest_url) return flask.redirect(dest_url)
def do_module_edit(val): def do_module_edit(vals: dict) -> None:
"edit a module" "edit a module"
from app.scodoc import sco_edit_formation from app.scodoc import sco_edit_formation
# check # 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"]): if module_is_locked(mod["module_id"]):
# formation verrouillée: empeche de modifier certains champs: # formation verrouillée: empeche de modifier certains champs:
protected_fields = ("coefficient", "ue_id", "matiere_id", "semestre_id") protected_fields = ("coefficient", "ue_id", "matiere_id", "semestre_id")
for f in protected_fields: for f in protected_fields:
if f in val: if f in vals:
del val[f] del vals[f]
# edit # edit
cnx = ndb.GetDBConnexion() cnx = ndb.GetDBConnexion()
_moduleEditor.edit(cnx, val) _moduleEditor.edit(cnx, vals)
Formation.query.get(mod["formation_id"]).invalidate_cached_sems() Formation.query.get(mod["formation_id"]).invalidate_cached_sems()
@ -604,6 +605,7 @@ def module_edit(module_id=None):
"title": "Code Apogée", "title": "Code Apogée",
"size": 25, "size": 25,
"explanation": "(optionnel) code élément pédagogique Apogée ou liste de codes ELP séparés par des virgules", "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,
}, },
), ),
( (

View File

@ -33,6 +33,7 @@ from flask import url_for, render_template
from flask import g, request from flask import g, request
from flask_login import current_user from flask_login import current_user
from app.models import APO_CODE_STR_LEN
from app.models import Formation, UniteEns, ModuleImpl, Module from app.models import Formation, UniteEns, ModuleImpl, Module
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu 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", "title": "Code Apogée",
"size": 25, "size": 25,
"explanation": "(optionnel) code élément pédagogique Apogée ou liste de codes ELP séparés par des virgules", "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,
}, },
), ),
( (

View File

@ -33,6 +33,7 @@ from flask_login import current_user
from app import db from app import db
from app.auth.models import User from app.auth.models import User
from app.models import APO_CODE_STR_LEN, SHORT_STR_LEN
from app.models import ModuleImpl, Evaluation, EvaluationUEPoids from app.models import ModuleImpl, Evaluation, EvaluationUEPoids
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
@ -359,6 +360,7 @@ def do_formsemestre_createwithmodules(edit=False):
mf_manual = { mf_manual = {
"size": 12, "size": 12,
"template": '<tr%(item_dom_attr)s><td class="tf-fieldlabel">%(label)s</td><td class="tf-field">%(elem)s', "template": '<tr%(item_dom_attr)s><td class="tf-fieldlabel">%(label)s</td><td class="tf-field">%(elem)s',
"validator": lambda val, _: len(val) < APO_CODE_STR_LEN,
} }
if etapes: if etapes:
mf = { mf = {
@ -495,6 +497,7 @@ def do_formsemestre_createwithmodules(edit=False):
"size": 8, "size": 8,
"title": "Couleur fond des bulletins", "title": "Couleur fond des bulletins",
"explanation": "version web seulement (ex: #ffeeee)", "explanation": "version web seulement (ex: #ffeeee)",
"validator": lambda val, _: len(val) < SHORT_STR_LEN,
}, },
), ),
( (

View File

@ -45,6 +45,7 @@ from flask import g, request
from flask import url_for, make_response from flask import url_for, make_response
from app import db from app import db
from app.models import GROUPNAME_STR_LEN, SHORT_STR_LEN
from app.models.groups import Partition from app.models.groups import Partition
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
@ -870,10 +871,11 @@ def editPartitionForm(formsemestre_id=None):
page_title="Partitions...", page_title="Partitions...",
javascripts=["js/editPartitionForm.js"], javascripts=["js/editPartitionForm.js"],
), ),
# limite à SHORT_STR_LEN
r"""<script type="text/javascript"> r"""<script type="text/javascript">
function checkname() { function checkname() {
var val = document.editpart.partition_name.value.replace(/^\s+/, "").replace(/\s+$/, ""); var val = document.editpart.partition_name.value.replace(/^\s+/, "").replace(/\s+$/, "");
if (val.length > 0) { if ((val.length > 0)&&(val.length < 32)) {
document.editpart.ok.disabled = false; document.editpart.ok.disabled = false;
} else { } else {
document.editpart.ok.disabled = true; document.editpart.ok.disabled = true;
@ -1124,6 +1126,7 @@ def partition_rename(partition_id):
"default": partition["partition_name"], "default": partition["partition_name"],
"allow_null": False, "allow_null": False,
"size": 12, "size": 12,
"validator": lambda val, _: len(val) < SHORT_STR_LEN,
}, },
), ),
), ),
@ -1231,6 +1234,7 @@ def group_rename(group_id):
"default": group["group_name"], "default": group["group_name"],
"size": 12, "size": 12,
"allow_null": False, "allow_null": False,
"validator": lambda val, _: len(val) < GROUPNAME_STR_LEN,
}, },
), ),
), ),

View File

@ -256,6 +256,10 @@ function createGroup() {
alert("Nom de groupe vide !"); alert("Nom de groupe vide !");
return false; return false;
} }
if (group_name.length >= 32) { // SHORT_STR_LEN
alert("Nom de groupe trop long !");
return false;
}
// check name: // check name:
for (var group_id in groupBoxes) { for (var group_id in groupBoxes) {
if (group_id != 'extend') { if (group_id != 'extend') {

View File

@ -1,4 +1,4 @@
{# -*- mode: jinja-html -*- #}
{{ sco_header|safe }} {{ sco_header|safe }}
<h2 class="formsemestre">Affectation aux groupes de {{ partition["partition_name"] }}</h2> <h2 class="formsemestre">Affectation aux groupes de {{ partition["partition_name"] }}</h2>