forked from ScoDoc/ScoDoc
Merge branch 'master' of https://scodoc.org/git/viennet/ScoDoc
This commit is contained in:
commit
f385f46897
@ -280,8 +280,9 @@ class ScoExcelSheet:
|
|||||||
cell.alignment = style["alignment"]
|
cell.alignment = style["alignment"]
|
||||||
if not comment is None:
|
if not comment is None:
|
||||||
cell.comment = Comment(comment, "scodoc")
|
cell.comment = Comment(comment, "scodoc")
|
||||||
cell.comment.width = 400
|
lines = comment.splitlines()
|
||||||
cell.comment.height = 150
|
cell.comment.width = 7 * max([len(line) for line in lines])
|
||||||
|
cell.comment.height = 20 * len(lines)
|
||||||
return cell
|
return cell
|
||||||
|
|
||||||
def make_row(self, values: list, style=None, comments=None):
|
def make_row(self, values: list, style=None, comments=None):
|
||||||
|
@ -142,25 +142,26 @@ def import_users(users, auth_dept=""):
|
|||||||
msg_list.append("Ligne %s : %s" % (line, msg))
|
msg_list.append("Ligne %s : %s" % (line, msg))
|
||||||
|
|
||||||
if len(users) == 0:
|
if len(users) == 0:
|
||||||
ok = False
|
import_ok = False
|
||||||
msg_list = ["Feuilles vide ou illisible"]
|
msg_list = ["Feuilles vide ou illisible"]
|
||||||
else:
|
else:
|
||||||
created = [] # liste de uid créés
|
created = [] # liste de uid créés
|
||||||
msg_list = []
|
msg_list = []
|
||||||
line = 1 # satr from excel line #2
|
line = 1 # satr from excel line #2
|
||||||
ok = True
|
import_ok = True
|
||||||
try:
|
try:
|
||||||
for u in users:
|
for u in users:
|
||||||
|
user_ok = True
|
||||||
line = line + 1
|
line = line + 1
|
||||||
ok, msg = sco_users.check_modif_user(
|
user_ok, msg = sco_users.check_modif_user(
|
||||||
0,
|
0,
|
||||||
user_name=u["user_name"],
|
user_name=u["user_name"],
|
||||||
nom=u["nom"],
|
nom=u["nom"],
|
||||||
prenom=u["prenom"],
|
prenom=u["prenom"],
|
||||||
email=u["email"],
|
email=u["email"],
|
||||||
roles=u["roles"],
|
roles=u["roles"].split(","),
|
||||||
)
|
)
|
||||||
if not ok:
|
if not user_ok:
|
||||||
append_msg("identifiant '%s' %s" % (u["user_name"], msg))
|
append_msg("identifiant '%s' %s" % (u["user_name"], msg))
|
||||||
# raise ScoValueError(
|
# raise ScoValueError(
|
||||||
# "données invalides pour %s: %s" % (u["user_name"], msg)
|
# "données invalides pour %s: %s" % (u["user_name"], msg)
|
||||||
@ -169,52 +170,56 @@ def import_users(users, auth_dept=""):
|
|||||||
#
|
#
|
||||||
# check identifiant
|
# check identifiant
|
||||||
if not re.match(r"^[a-zA-Z0-9@\\\-_\\\.]*$", u["user_name"]):
|
if not re.match(r"^[a-zA-Z0-9@\\\-_\\\.]*$", u["user_name"]):
|
||||||
ok = False
|
user_ok = False
|
||||||
append_msg(
|
append_msg(
|
||||||
"identifiant '%s' invalide (pas d'accents ni de caractères spéciaux)"
|
"identifiant '%s' invalide (pas d'accents ni de caractères spéciaux)"
|
||||||
% u["user_name"]
|
% u["user_name"]
|
||||||
)
|
)
|
||||||
elif len(u["user_name"]) > 64:
|
elif len(u["user_name"]) > 64:
|
||||||
ok = False
|
user_ok = False
|
||||||
append_msg(
|
append_msg(
|
||||||
"identifiant '%s' trop long (64 caractères)" % u["user_name"]
|
"identifiant '%s' trop long (64 caractères)" % u["user_name"]
|
||||||
)
|
)
|
||||||
if len(u["nom"]) > 64:
|
if len(u["nom"]) > 64:
|
||||||
ok = False
|
user_ok = False
|
||||||
append_msg("nom '%s' trop long (64 caractères)" % u["nom"])
|
append_msg("nom '%s' trop long (64 caractères)" % u["nom"])
|
||||||
if len(u["prenom"]) > 64:
|
if len(u["prenom"]) > 64:
|
||||||
ok = False
|
user_ok = False
|
||||||
append_msg("prenom '%s' trop long (64 caractères)" % u["prenom"])
|
append_msg("prenom '%s' trop long (64 caractères)" % u["prenom"])
|
||||||
if len(u["email"]) > 120:
|
if len(u["email"]) > 120:
|
||||||
ok = False
|
user_ok = False
|
||||||
append_msg("email '%s' trop long (120 caractères)" % u["email"])
|
append_msg("email '%s' trop long (120 caractères)" % u["email"])
|
||||||
# check département
|
# check département
|
||||||
if u["dept"] != "":
|
if u["dept"] != "":
|
||||||
dept = Departement.query.filter_by(acronym=u["dept"]).first()
|
dept = Departement.query.filter_by(acronym=u["dept"]).first()
|
||||||
if dept is None:
|
if dept is None:
|
||||||
ok = False
|
user_ok = False
|
||||||
append_msg("département '%s' inexistant" % u["dept"])
|
append_msg("département '%s' inexistant" % u["dept"])
|
||||||
for role in u["roles"].split(","):
|
for role in u["roles"].split(","):
|
||||||
try:
|
try:
|
||||||
_, _ = UserRole.role_dept_from_string(role)
|
_, _ = UserRole.role_dept_from_string(role)
|
||||||
except ScoValueError as value_error:
|
except ScoValueError as value_error:
|
||||||
ok = False
|
user_ok = False
|
||||||
append_msg("role : %s " % role)
|
append_msg("role : %s " % role)
|
||||||
# Création de l'utilisateur (via SQLAlchemy)
|
# Création de l'utilisateur (via SQLAlchemy)
|
||||||
if ok:
|
if user_ok:
|
||||||
|
created.append(u)
|
||||||
|
else:
|
||||||
|
import_ok = False
|
||||||
|
except ScoValueError as value_error:
|
||||||
|
log("import_users: exception: abort create %s" % str(created))
|
||||||
|
raise ScoValueError(msg) # re-raise exception
|
||||||
|
if import_ok:
|
||||||
|
for u in created:
|
||||||
|
u["roles_string"] = u["roles"]
|
||||||
user = User()
|
user = User()
|
||||||
user.from_dict(u, new_user=True)
|
user.from_dict(u, new_user=True)
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
created.append(u["user_name"])
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except ScoValueError as value_error:
|
mail_password(u)
|
||||||
log("import_users: exception: abort create %s" % str(created))
|
else:
|
||||||
db.session.rollback()
|
created = [] # reset # of created users to 0
|
||||||
raise ScoValueError(msg) # re-raise exception
|
return import_ok, msg_list, len(created)
|
||||||
|
|
||||||
for user in users:
|
|
||||||
mail_password(user)
|
|
||||||
return ok, msg_list
|
|
||||||
|
|
||||||
|
|
||||||
# --------- Génération du mot de passe initial -----------
|
# --------- Génération du mot de passe initial -----------
|
||||||
|
@ -469,7 +469,9 @@ def create_user_form(REQUEST, user_name=None, edit=0):
|
|||||||
def import_users_generate_excel_sample(REQUEST):
|
def import_users_generate_excel_sample(REQUEST):
|
||||||
"une feuille excel pour importation utilisateurs"
|
"une feuille excel pour importation utilisateurs"
|
||||||
data = sco_import_users.generate_excel_sample()
|
data = sco_import_users.generate_excel_sample()
|
||||||
return sco_excel.send_excel_file(REQUEST, data, "ImportUtilisateurs.xlsx")
|
return sco_excel.send_excel_file(
|
||||||
|
REQUEST, data, "ImportUtilisateurs" + scu.XLSX_SUFFIX
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/import_users_form", methods=["GET", "POST"])
|
@bp.route("/import_users_form", methods=["GET", "POST"])
|
||||||
@ -523,23 +525,18 @@ def import_users_form(REQUEST=None):
|
|||||||
if tf[0] == 0:
|
if tf[0] == 0:
|
||||||
return "\n".join(H) + tf[1] + "</li></ol>" + help + F
|
return "\n".join(H) + tf[1] + "</li></ol>" + help + F
|
||||||
elif tf[0] == -1:
|
elif tf[0] == -1:
|
||||||
return flask.redirect(url_for("scodoc.index"))
|
return flask.redirect(back_url)
|
||||||
else:
|
else:
|
||||||
# IMPORT
|
# IMPORT
|
||||||
ok, diag = sco_import_users.import_excel_file(tf[2]["xlsfile"])
|
ok, diag, nb_created = sco_import_users.import_excel_file(tf[2]["xlsfile"])
|
||||||
H = [
|
H = [html_sco_header.sco_header(page_title="Import utilisateurs")]
|
||||||
html_sco_header.sco_header(page_title="Import utilisateurs"),
|
H.append("<ul>")
|
||||||
"""<h2>Téléchargement d'une nouvelle liste d'utilisateurs</h2>
|
|
||||||
""",
|
|
||||||
]
|
|
||||||
if diag:
|
|
||||||
H.append("""<h3>Problèmes rencontrés:</h3><ul>""")
|
|
||||||
for d in diag:
|
for d in diag:
|
||||||
H.append(f"<li>{d}</li>")
|
H.append("<li>%s</li>" % d)
|
||||||
H.append("</ul>")
|
H.append("</ul>")
|
||||||
if ok:
|
if ok:
|
||||||
dest = url_for("users.index_html", scodoc_dept=g.scodoc_dept)
|
dest = url_for("users.index_html", scodoc_dept=g.scodoc_dept)
|
||||||
H.append("<p>Ok, Import terminé !</p>")
|
H.append("<p>Ok, Import terminé (%s utilisateurs créés)!</p>" % nb_created)
|
||||||
H.append('<p><a class="stdlink" href="%s">Continuer</a></p>' % dest)
|
H.append('<p><a class="stdlink" href="%s">Continuer</a></p>' % dest)
|
||||||
else:
|
else:
|
||||||
dest = url_for("users.import_users_form", scodoc_dept=g.scodoc_dept)
|
dest = url_for("users.import_users_form", scodoc_dept=g.scodoc_dept)
|
||||||
|
Loading…
Reference in New Issue
Block a user