diff --git a/app/scodoc/sco_import_etuds.py b/app/scodoc/sco_import_etuds.py
index 6d4988d17c..da117b5d0b 100644
--- a/app/scodoc/sco_import_etuds.py
+++ b/app/scodoc/sco_import_etuds.py
@@ -154,9 +154,9 @@ def sco_import_generate_excel_sample(
with_codesemestre=True,
only_tables=None,
with_groups=True,
- exclude_cols=[],
- extra_cols=[],
- group_ids=[],
+ exclude_cols=(),
+ extra_cols=(),
+ group_ids=(),
):
"""Generates an excel document based on format fmt
(format is the result of sco_import_format())
@@ -167,7 +167,7 @@ def sco_import_generate_excel_sample(
style = sco_excel.excel_make_style(bold=True)
style_required = sco_excel.excel_make_style(bold=True, color=COLORS.RED)
titles = []
- titlesStyles = []
+ titles_styles = []
for l in fmt:
name = l[0].lower()
if (not with_codesemestre) and name == "codesemestre":
@@ -177,15 +177,15 @@ def sco_import_generate_excel_sample(
if name in exclude_cols:
continue # colonne exclue
if int(l[3]):
- titlesStyles.append(style)
+ titles_styles.append(style)
else:
- titlesStyles.append(style_required)
+ titles_styles.append(style_required)
titles.append(name)
if with_groups and "groupes" not in titles:
titles.append("groupes")
- titlesStyles.append(style)
+ titles_styles.append(style)
titles += extra_cols
- titlesStyles += [style] * len(extra_cols)
+ titles_styles += [style] * len(extra_cols)
if group_ids:
groups_infos = sco_groups_view.DisplayedGroupsInfos(group_ids)
members = groups_infos.members
@@ -194,7 +194,7 @@ def sco_import_generate_excel_sample(
% (group_ids, len(members))
)
titles = ["etudid"] + titles
- titlesStyles = [style] + titlesStyles
+ titles_styles = [style] + titles_styles
# rempli table avec données actuelles
lines = []
for i in members:
@@ -213,7 +213,7 @@ def sco_import_generate_excel_sample(
else:
lines = [[]] # empty content, titles only
return sco_excel.excel_simple_table(
- titles=titles, titles_styles=titlesStyles, sheet_name="Etudiants", lines=lines
+ titles=titles, titles_styles=titles_styles, sheet_name="Etudiants", lines=lines
)
@@ -256,7 +256,7 @@ def scolars_import_excel_file(
formsemestre_id=None,
check_homonyms=True,
require_ine=False,
- exclude_cols=[],
+ exclude_cols=(),
):
"""Importe etudiants depuis fichier Excel
et les inscrit dans le semestre indiqué (et à TOUS ses modules)
@@ -302,7 +302,8 @@ def scolars_import_excel_file(
else:
unknown.append(f)
raise ScoValueError(
- "Nombre de colonnes incorrect (devrait être %d, et non %d)
(colonnes manquantes: %s, colonnes invalides: %s)"
+ """Nombre de colonnes incorrect (devrait être %d, et non %d)
+ (colonnes manquantes: %s, colonnes invalides: %s)"""
% (len(titles), len(fs), list(missing.keys()), unknown)
)
titleslist = []
@@ -313,7 +314,7 @@ def scolars_import_excel_file(
# ok, same titles
# Start inserting data, abort whole transaction in case of error
created_etudids = []
- NbImportedHomonyms = 0
+ np_imported_homonyms = 0
GroupIdInferers = {}
try: # --- begin DB transaction
linenum = 0
@@ -377,10 +378,10 @@ def scolars_import_excel_file(
if val:
try:
val = sco_excel.xldate_as_datetime(val)
- except ValueError:
+ except ValueError as exc:
raise ScoValueError(
f"date invalide ({val}) sur ligne {linenum}, colonne {titleslist[i]}"
- )
+ ) from exc
# INE
if (
titleslist[i].lower() == "code_ine"
@@ -404,15 +405,17 @@ def scolars_import_excel_file(
if values["code_ine"] and not is_new_ine:
raise ScoValueError("Code INE dupliqué (%s)" % values["code_ine"])
# Check nom/prenom
- ok, NbHomonyms = sco_etud.check_nom_prenom(
- cnx, nom=values["nom"], prenom=values["prenom"]
- )
+ ok = False
+ if "nom" in values and "prenom" in values:
+ ok, nb_homonyms = sco_etud.check_nom_prenom(
+ cnx, nom=values["nom"], prenom=values["prenom"]
+ )
if not ok:
raise ScoValueError(
"nom ou prénom invalide sur la ligne %d" % (linenum)
)
- if NbHomonyms:
- NbImportedHomonyms += 1
+ if nb_homonyms:
+ np_imported_homonyms += 1
# Insert in DB tables
formsemestre_id_etud = _import_one_student(
cnx,
@@ -425,11 +428,11 @@ def scolars_import_excel_file(
)
# Verification proportion d'homonymes: si > 10%, abandonne
- log("scolars_import_excel_file: detected %d homonyms" % NbImportedHomonyms)
- if check_homonyms and NbImportedHomonyms > len(created_etudids) / 10:
+ log("scolars_import_excel_file: detected %d homonyms" % np_imported_homonyms)
+ if check_homonyms and np_imported_homonyms > len(created_etudids) / 10:
log("scolars_import_excel_file: too many homonyms")
raise ScoValueError(
- "Il y a trop d'homonymes (%d étudiants)" % NbImportedHomonyms
+ "Il y a trop d'homonymes (%d étudiants)" % np_imported_homonyms
)
except:
cnx.rollback()