forked from ScoDoc/DocScoDoc
permet de lever certaines vérifications lors de l import
This commit is contained in:
parent
f0d641a31e
commit
9c528bec7f
@ -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"],
|
||||
|
@ -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: "
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user