forked from ScoDoc/ScoDoc
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:
commit
a539061c1f
@ -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.
|
Import scodoc users from Excel file.
|
||||||
This method:
|
This method:
|
||||||
@ -134,10 +134,10 @@ def import_excel_file(datafile):
|
|||||||
d[fs[i]] = line[i]
|
d[fs[i]] = line[i]
|
||||||
users.append(d)
|
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.
|
Import users from a list of users_descriptors.
|
||||||
|
|
||||||
@ -178,8 +178,7 @@ def import_users(users):
|
|||||||
line = line + 1
|
line = line + 1
|
||||||
user_ok, msg = sco_users.check_modif_user(
|
user_ok, msg = sco_users.check_modif_user(
|
||||||
0,
|
0,
|
||||||
ignore_optionals=False,
|
enforce_optionals=not force,
|
||||||
ajout_en_masse=True,
|
|
||||||
user_name=u["user_name"],
|
user_name=u["user_name"],
|
||||||
nom=u["nom"],
|
nom=u["nom"],
|
||||||
prenom=u["prenom"],
|
prenom=u["prenom"],
|
||||||
|
@ -387,8 +387,7 @@ def user_info_page(user_name=None):
|
|||||||
|
|
||||||
def check_modif_user(
|
def check_modif_user(
|
||||||
edit,
|
edit,
|
||||||
ignore_optionals=False,
|
enforce_optionals=False,
|
||||||
ajout_en_masse=False,
|
|
||||||
user_name="",
|
user_name="",
|
||||||
nom="",
|
nom="",
|
||||||
prenom="",
|
prenom="",
|
||||||
@ -403,11 +402,6 @@ def check_modif_user(
|
|||||||
(si ok est faux, l'utilisateur peut quand même forcer la creation)
|
(si ok est faux, l'utilisateur peut quand même forcer la creation)
|
||||||
- msg: message warning à presenter à l'utilisateur
|
- 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)"""
|
MSG_OPT = """<br/>Attention: (vous pouvez forcer l'opération en cochant "<em>Ignorer les avertissements</em>" en bas de page)"""
|
||||||
# ce login existe ?
|
# ce login existe ?
|
||||||
user = _user_list(user_name)
|
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)"
|
"identifiant '%s' invalide (pas d'accents ni de caractères spéciaux)"
|
||||||
% user_name,
|
% 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
|
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
|
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
|
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
|
# check that tha same user_name has not already been described in this import
|
||||||
if not email:
|
if not email:
|
||||||
@ -438,12 +432,12 @@ def check_modif_user(
|
|||||||
return False, "l'adresse mail semble incorrecte"
|
return False, "l'adresse mail semble incorrecte"
|
||||||
# check département
|
# check département
|
||||||
if (
|
if (
|
||||||
ignore_optionals
|
enforce_optionals
|
||||||
and dept != ""
|
and dept != ""
|
||||||
and Departement.query.filter_by(acronym=dept).first() is None
|
and Departement.query.filter_by(acronym=dept).first() is None
|
||||||
):
|
):
|
||||||
return False, "département '%s' inexistant" % dept + MSG_OPT
|
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
|
return False, "aucun rôle sélectionné, êtes vous sûr ?" + MSG_OPT
|
||||||
# ok
|
# ok
|
||||||
# Des noms/prénoms semblables existent ?
|
# Des noms/prénoms semblables existent ?
|
||||||
@ -456,7 +450,7 @@ def check_modif_user(
|
|||||||
minmatch = 1
|
minmatch = 1
|
||||||
else:
|
else:
|
||||||
minmatch = 0
|
minmatch = 0
|
||||||
if len(similar_users) > minmatch:
|
if enforce_optionals and len(similar_users) > minmatch:
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
"des utilisateurs proches existent: "
|
"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
|
return "\n".join(H) + "\n" + tf[1] + F
|
||||||
ok, msg = sco_users.check_modif_user(
|
ok, msg = sco_users.check_modif_user(
|
||||||
edit,
|
edit,
|
||||||
ignore_optionals=not force,
|
enforce_optionals=not force,
|
||||||
user_name=user_name,
|
user_name=user_name,
|
||||||
nom=vals["nom"],
|
nom=vals["nom"],
|
||||||
prenom=vals["prenom"],
|
prenom=vals["prenom"],
|
||||||
@ -531,6 +531,16 @@ def import_users_form():
|
|||||||
"xlsfile",
|
"xlsfile",
|
||||||
{"title": "Fichier Excel:", "input_type": "file", "size": 40},
|
{"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"}),
|
("formsemestre_id", {"input_type": "hidden"}),
|
||||||
),
|
),
|
||||||
submitlabel="Télécharger",
|
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))
|
return flask.redirect(url_for("scolar.index_html", docodc_dept=g.scodoc_dept))
|
||||||
else:
|
else:
|
||||||
# IMPORT
|
# 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 = [html_sco_header.sco_header(page_title="Import utilisateurs")]
|
||||||
H.append("<ul>")
|
H.append("<ul>")
|
||||||
for d in diag:
|
for d in diag:
|
||||||
|
Loading…
Reference in New Issue
Block a user