From 9c528bec7ffc3e4fc29ad5fa5d78fe7b940102c2 Mon Sep 17 00:00:00 2001 From: Jean-Marie Place Date: Wed, 13 Oct 2021 16:32:43 +0200 Subject: [PATCH] =?UTF-8?q?permet=20de=20lever=20certaines=20v=C3=A9rifica?= =?UTF-8?q?tions=20lors=20de=20l=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_import_users.py | 9 ++++----- app/scodoc/sco_users.py | 22 ++++++++-------------- app/views/users.py | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/scodoc/sco_import_users.py b/app/scodoc/sco_import_users.py index 834b8886..804cb6ac 100644 --- a/app/scodoc/sco_import_users.py +++ b/app/scodoc/sco_import_users.py @@ -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"], diff --git a/app/scodoc/sco_users.py b/app/scodoc/sco_users.py index a8d15e96..be43125d 100644 --- a/app/scodoc/sco_users.py +++ b/app/scodoc/sco_users.py @@ -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,12 +402,7 @@ 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 = ( - """
Impossible de forcer l'opération lors d'une importation en masse""" - ) - else: - MSG_OPT = """
Attention: (vous pouvez forcer l'opération en cochant "Ignorer les avertissements" en bas de page)""" + MSG_OPT = """
Attention: (vous pouvez forcer l'opération en cochant "Ignorer les avertissements" en bas de page)""" # ce login existe ? user = _user_list(user_name) if edit and not user: # safety net, le user_name ne devrait pas changer @@ -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: " diff --git a/app/views/users.py b/app/views/users.py index 93687fce..cddcf195 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -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("