Merge pull request 'permet de lever certaines vérifications lors de l import' (#161) from jmplace/ScoDoc-Lille:import_users_release_some_checks into master

Reviewed-on: https://scodoc.org/git/viennet/ScoDoc/pulls/161
This commit is contained in:
Emmanuel Viennet 2021-10-13 21:31:41 +02:00
commit a539061c1f
3 changed files with 26 additions and 21 deletions

View File

@ -82,7 +82,7 @@ def generate_excel_sample():
)
def import_excel_file(datafile):
def import_excel_file(datafile, force=""):
"""
Import scodoc users from Excel file.
This method:
@ -134,10 +134,10 @@ def import_excel_file(datafile):
d[fs[i]] = line[i]
users.append(d)
return import_users(users)
return import_users(users=users, force=force)
def import_users(users):
def import_users(users, force=""):
"""
Import users from a list of users_descriptors.
@ -178,8 +178,7 @@ def import_users(users):
line = line + 1
user_ok, msg = sco_users.check_modif_user(
0,
ignore_optionals=False,
ajout_en_masse=True,
enforce_optionals=not force,
user_name=u["user_name"],
nom=u["nom"],
prenom=u["prenom"],

View File

@ -387,8 +387,7 @@ def user_info_page(user_name=None):
def check_modif_user(
edit,
ignore_optionals=False,
ajout_en_masse=False,
enforce_optionals=False,
user_name="",
nom="",
prenom="",
@ -403,11 +402,6 @@ def check_modif_user(
(si ok est faux, l'utilisateur peut quand même forcer la creation)
- msg: message warning à presenter à l'utilisateur
"""
if ajout_en_masse:
MSG_OPT = (
"""<br/>Impossible de forcer l'opération lors d'une importation en masse"""
)
else:
MSG_OPT = """<br/>Attention: (vous pouvez forcer l'opération en cochant "<em>Ignorer les avertissements</em>" en bas de page)"""
# ce login existe ?
user = _user_list(user_name)
@ -423,11 +417,11 @@ def check_modif_user(
"identifiant '%s' invalide (pas d'accents ni de caractères spéciaux)"
% user_name,
)
if ignore_optionals and len(user_name) > 64:
if enforce_optionals and len(user_name) > 64:
return False, "identifiant '%s' trop long (64 caractères)" % user_name
if ignore_optionals and len(nom) > 64:
if enforce_optionals and len(nom) > 64:
return False, "nom '%s' trop long (64 caractères)" % nom + MSG_OPT
if ignore_optionals and len(prenom) > 64:
if enforce_optionals and len(prenom) > 64:
return False, "prenom '%s' trop long (64 caractères)" % prenom + MSG_OPT
# check that tha same user_name has not already been described in this import
if not email:
@ -438,12 +432,12 @@ def check_modif_user(
return False, "l'adresse mail semble incorrecte"
# check département
if (
ignore_optionals
enforce_optionals
and dept != ""
and Departement.query.filter_by(acronym=dept).first() is None
):
return False, "département '%s' inexistant" % dept + MSG_OPT
if ignore_optionals and not roles:
if enforce_optionals and not roles:
return False, "aucun rôle sélectionné, êtes vous sûr ?" + MSG_OPT
# ok
# Des noms/prénoms semblables existent ?
@ -456,7 +450,7 @@ def check_modif_user(
minmatch = 1
else:
minmatch = 0
if len(similar_users) > minmatch:
if enforce_optionals and len(similar_users) > minmatch:
return (
False,
"des utilisateurs proches existent: "

View File

@ -382,7 +382,7 @@ def create_user_form(user_name=None, edit=0, all_roles=1):
return "\n".join(H) + "\n" + tf[1] + F
ok, msg = sco_users.check_modif_user(
edit,
ignore_optionals=not force,
enforce_optionals=not force,
user_name=user_name,
nom=vals["nom"],
prenom=vals["prenom"],
@ -531,6 +531,16 @@ def import_users_form():
"xlsfile",
{"title": "Fichier Excel:", "input_type": "file", "size": 40},
),
(
"force",
{
"title": "Ignorer les avertissements",
"input_type": "checkbox",
"explanation": "passer outre les avertissements (homonymes, etc)",
"labels": ("",),
"allowed_values": ("1",),
},
),
("formsemestre_id", {"input_type": "hidden"}),
),
submitlabel="Télécharger",
@ -541,7 +551,9 @@ def import_users_form():
return flask.redirect(url_for("scolar.index_html", docodc_dept=g.scodoc_dept))
else:
# IMPORT
ok, diag, nb_created = sco_import_users.import_excel_file(tf[2]["xlsfile"])
ok, diag, nb_created = sco_import_users.import_excel_file(
tf[2]["xlsfile"], tf[2]["force"]
)
H = [html_sco_header.sco_header(page_title="Import utilisateurs")]
H.append("<ul>")
for d in diag: