pylint corrections (suite)

This commit is contained in:
Jean-Marie Place 2021-09-17 12:18:55 +02:00
parent b03eee12a1
commit 6e7a104fb0
2 changed files with 71 additions and 53 deletions

View File

@ -70,11 +70,31 @@ import sco_version
COORD = "Coordonnées" COORD = "Coordonnées"
SEQ = "Continue" SEQ = "Continue"
TOUS = "Tous"
def _get_group_info(evaluation_id):
# groupes
groups = sco_groups.do_evaluation_listegroupes(
evaluation_id, include_default=True
)
has_groups = False
groups_tree = {}
for group in groups:
partition = group["partition_name"] or TOUS
group_id = group["group_id"]
group_name = group["group_name"] or TOUS
if partition not in groups_tree:
groups_tree[partition] = {}
groups_tree[partition][group_name] = group_id
if partition != TOUS:
has_groups = True
nb_groups = len(groups_tree)
return groups_tree, has_groups, nb_groups
class PlacementForm(FlaskForm): class PlacementForm(FlaskForm):
"""Formulaire pour placement des étudiants en Salle""" """Formulaire pour placement des étudiants en Salle"""
TOUS = "Tous"
evaluation_id = HiddenField("evaluation_id") evaluation_id = HiddenField("evaluation_id")
file_format = RadioField( file_format = RadioField(
"Format de fichier", "Format de fichier",
@ -104,27 +124,20 @@ class PlacementForm(FlaskForm):
) )
submit = SubmitField("OK") submit = SubmitField("OK")
def __init__(self, formdata=None, data=None):
super().__init__(formdata=formdata, data=data)
self.groups_tree = {}
self.has_groups = None
self.group_tree_length = None
self.nb_groups = None
self.set_evaluation_infos(data["evaluation_id"])
def set_evaluation_infos(self, evaluation_id): def set_evaluation_infos(self, evaluation_id):
"""Initialise les données du formulaire avec les données de l'évaluation.""" """Initialise les données du formulaire avec les données de l'évaluation."""
eval_data = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id}) eval_data = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id})
if not eval_data: if not eval_data:
raise ScoValueError("invalid evaluation_id") raise ScoValueError("invalid evaluation_id")
# groupes self.groups_tree, self.has_groups, self.nb_groups = _get_group_info(evaluation_id)
groups = sco_groups.do_evaluation_listegroupes(
evaluation_id, include_default=True
)
self.groups_tree = {}
self.has_groups = False
for group in groups:
partition = group["partition_name"] or self.TOUS
group_id = group["group_id"]
group_name = group["group_name"] or self.TOUS
if partition not in self.groups_tree:
self.groups_tree[partition] = {}
self.groups_tree[partition][group_name] = group_id
if partition != self.TOUS:
self.has_groups = True
self.groups_tree_length = len(self.groups_tree)
if self.has_groups: if self.has_groups:
choices = [] choices = []
for partition in self.groups_tree: for partition in self.groups_tree:
@ -141,6 +154,7 @@ class _DistributeurContinu:
self.position = 1 self.position = 1
def suivant(self): def suivant(self):
"""Retounre la désignation de la place suivante"""
retour = self.position retour = self.position
self.position += 1 self.position += 1
return retour return retour
@ -155,6 +169,7 @@ class _Distributeur2D:
self.index = 1 self.index = 1
def suivant(self): def suivant(self):
"""Retounre la désignation de la place suivante"""
retour = (self.index, self.rang) retour = (self.index, self.rang)
self.rang += 1 self.rang += 1
if self.rang > self.nb_rangs: if self.rang > self.nb_rangs:
@ -167,9 +182,8 @@ def placement_eval_selectetuds(evaluation_id):
"""Creation de l'écran de placement""" """Creation de l'écran de placement"""
form = PlacementForm( form = PlacementForm(
request.form, request.form,
data={"evaluation_id": int(evaluation_id), "groups": PlacementForm.TOUS}, data={"evaluation_id": int(evaluation_id), "groups": TOUS},
) )
form.set_evaluation_infos(evaluation_id)
if form.validate_on_submit(): if form.validate_on_submit():
runner = PlacementRunner(form) runner = PlacementRunner(form)
if not runner.check_placement(): if not runner.check_placement():
@ -195,6 +209,7 @@ def placement_eval_selectetuds(evaluation_id):
class PlacementRunner: class PlacementRunner:
"""Execution de l'action définie par le formulaire""" """Execution de l'action définie par le formulaire"""
def __init__(self, form): def __init__(self, form):
"""Calcul et génération du fichier sur la base des données du formulaire""" """Calcul et génération du fichier sur la base des données du formulaire"""
self.evaluation_id = form["evaluation_id"].data self.evaluation_id = form["evaluation_id"].data
@ -239,6 +254,9 @@ class PlacementRunner:
"Controle : %s (coef. %g)" "Controle : %s (coef. %g)"
% (self.evaltitre, self.eval_data["coefficient"]), % (self.evaltitre, self.eval_data["coefficient"]),
] ]
self.styles = None
self.plan = None
self.listetud = None
def check_placement(self): def check_placement(self):
"""Vérifie que l'utilisateur courant a le droit d'édition sur les notes""" """Vérifie que l'utilisateur courant a le droit d'édition sur les notes"""
@ -248,6 +266,7 @@ class PlacementRunner:
) )
def exec_placement(self): def exec_placement(self):
"""Excéute l'action liée au formulaire"""
self._repartition() self._repartition()
if self.file_format == "xls": if self.file_format == "xls":
return self._production_xls() return self._production_xls()
@ -263,14 +282,11 @@ class PlacementRunner:
self.plan = self._affectation_places() self.plan = self._affectation_places()
def _build_listetud(self): def _build_listetud(self):
if None in [g["group_name"] for g in self.groups]: # tous les etudiants get_all_students = None in [g["group_name"] for g in self.groups] # tous les etudiants
getallstudents = True
else:
getallstudents = False
etudids = sco_groups.do_evaluation_listeetuds_groups( etudids = sco_groups.do_evaluation_listeetuds_groups(
self.evaluation_id, self.evaluation_id,
self.groups, self.groups,
getallstudents=getallstudents, getallstudents=get_all_students,
include_dems=True, include_dems=True,
) )
listetud = [] # liste de couples (nom,prenom) listetud = [] # liste de couples (nom,prenom)
@ -359,24 +375,24 @@ class PlacementRunner:
) )
return tab.make_page(format="pdf", with_html_headers=False) return tab.make_page(format="pdf", with_html_headers=False)
def _one_header(self, ws): def _one_header(self, worksheet):
cells = [ cells = [
ws.make_cell("Nom", self.styles["2bi"]), worksheet.make_cell("Nom", self.styles["2bi"]),
ws.make_cell("Prénom", self.styles["2bi"]), worksheet.make_cell("Prénom", self.styles["2bi"]),
] ]
if self.etiquetage == COORD: if self.etiquetage == COORD:
cells.append(ws.make_cell("Colonne", self.styles["2bi"])) cells.append(worksheet.make_cell("Colonne", self.styles["2bi"]))
cells.append(ws.make_cell("Ligne", self.styles["2bi"])) cells.append(worksheet.make_cell("Ligne", self.styles["2bi"]))
else: else:
cells.append(ws.make_cell("Place", self.styles["2bi"])) cells.append(worksheet.make_cell("Place", self.styles["2bi"]))
return cells return cells
def _headers(self, ws, nb_listes): def _headers(self, worksheet, nb_listes):
cells = [] cells = []
for _ in range(nb_listes): for _ in range(nb_listes):
cells += self._one_header(ws) cells += self._one_header(worksheet)
cells.append(ws.make_cell("")) cells.append(worksheet.make_cell(""))
ws.append_row(cells) worksheet.append_row(cells)
def _make_styles(self, ws0, ws1): def _make_styles(self, ws0, ws1):
# polices # polices
@ -515,7 +531,7 @@ class PlacementRunner:
ws0.append_row(cells_c) ws0.append_row(cells_c)
ws0.set_row_dimension_height(row, space / 25) ws0.set_row_dimension_height(row, space / 25)
def _feuille1(self, ws, maxlines): def _feuille1(self, worksheet, maxlines):
# etudiants - feuille1 # etudiants - feuille1
# structuration: # structuration:
# 1 page = maxlistes listes # 1 page = maxlistes listes
@ -529,13 +545,13 @@ class PlacementRunner:
widths = [] widths = []
for _ in range(maxlistes): for _ in range(maxlistes):
widths += gabarit widths += gabarit
ws.set_column_dimension_width(value=widths) worksheet.set_column_dimension_width(value=widths)
nb_etu_restant = len(self.listetud) nb_etu_restant = len(self.listetud)
self._titres(ws) self._titres(worksheet)
nb_listes = min( nb_listes = min(
maxlistes, nb_etu_restant // maxlines + 1 maxlistes, nb_etu_restant // maxlines + 1
) # nombre de colonnes dans la page ) # nombre de colonnes dans la page
self._headers(ws, nb_listes) self._headers(worksheet, nb_listes)
# construction liste alphabétique # construction liste alphabétique
# Affichage # Affichage
lines = [[] for _ in range(maxlines)] lines = [[] for _ in range(maxlines)]
@ -544,31 +560,33 @@ class PlacementRunner:
for etud in sorted(self.plan, key=lambda e: e[0][0]): # tri alphabétique for etud in sorted(self.plan, key=lambda e: e[0][0]): # tri alphabétique
# check for skip of list or page # check for skip of list or page
if col > 0: # add a empty cell between lists if col > 0: # add a empty cell between lists
lines[lineno].append(ws.make_cell()) lines[lineno].append(worksheet.make_cell())
lines[lineno].append(ws.make_cell(etud[0][0], self.styles["2l"])) lines[lineno].append(worksheet.make_cell(etud[0][0], self.styles["2l"]))
lines[lineno].append(ws.make_cell(etud[0][1], self.styles["2m1"])) lines[lineno].append(worksheet.make_cell(etud[0][1], self.styles["2m1"]))
if self.etiquetage == COORD: if self.etiquetage == COORD:
lines[lineno].append(ws.make_cell(etud[1][1], self.styles["2m2"])) lines[lineno].append(
lines[lineno].append(ws.make_cell(etud[1][0], self.styles["2r"])) worksheet.make_cell(etud[1][1], self.styles["2m2"])
)
lines[lineno].append(worksheet.make_cell(etud[1][0], self.styles["2r"]))
else: else:
lines[lineno].append(ws.make_cell(etud[1], self.styles["2r"])) lines[lineno].append(worksheet.make_cell(etud[1], self.styles["2r"]))
lineno = lineno + 1 lineno = lineno + 1
if lineno >= maxlines: # fin de liste if lineno >= maxlines: # fin de liste
col = col + 1 col = col + 1
lineno = 0 lineno = 0
if col >= maxlistes: # fin de page if col >= maxlistes: # fin de page
for line_cells in lines: for line_cells in lines:
ws.append_row(line_cells) worksheet.append_row(line_cells)
lines = [[] for _ in range(maxlines)] lines = [[] for _ in range(maxlines)]
col = 0 col = 0
ws.append_blank_row() worksheet.append_blank_row()
nb_etu_restant -= maxlistes * maxlines nb_etu_restant -= maxlistes * maxlines
nb_listes = min( nb_listes = min(
maxlistes, nb_etu_restant // maxlines + 1 maxlistes, nb_etu_restant // maxlines + 1
) # nombre de colonnes dans la page ) # nombre de colonnes dans la page
self._headers(ws, nb_listes) self._headers(worksheet, nb_listes)
for line_cells in lines: for line_cells in lines:
ws.append_row(line_cells) worksheet.append_row(line_cells)
def _excel_feuille_placement(self): def _excel_feuille_placement(self):
"""Genere feuille excel pour placement des etudiants. """Genere feuille excel pour placement des etudiants.
@ -586,8 +604,8 @@ class PlacementRunner:
workbook = ScoExcelBook() workbook = ScoExcelBook()
SheetName0 = "Emargement" sheet_name_0 = "Emargement"
ws0 = workbook.create_sheet(SheetName0) ws0 = workbook.create_sheet(sheet_name_0)
# ajuste largeurs colonnes (unite inconnue, empirique) # ajuste largeurs colonnes (unite inconnue, empirique)
width = 4500 * column_width_ratio width = 4500 * column_width_ratio
if nb_rangs > 5: if nb_rangs > 5:
@ -599,8 +617,8 @@ class PlacementRunner:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[col + 1 : col + 2], width "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[col + 1 : col + 2], width
) )
SheetName1 = "Positions" sheet_name_1 = "Positions"
ws1 = workbook.create_sheet(SheetName1) ws1 = workbook.create_sheet(sheet_name_1)
self._make_styles(ws0, ws1) self._make_styles(ws0, ws1)
self._feuille0(ws0, space) self._feuille0(ws0, space)

View File

@ -32,7 +32,7 @@
{% for partition in form.groups_tree %} {% for partition in form.groups_tree %}
<tr> <tr>
{% if partition == 'Tous' %} {% if partition == 'Tous' %}
<td rowspan="{{ form.groups_tree_length }}">Groupes</td> <td rowspan="{{ form.nb_groups }}">Groupes</td>
{% endif %} {% endif %}
<td>{{ partition }}</td> <td>{{ partition }}</td>
<td> <td>