diff --git a/app/forms/scolar/groups_form.py b/app/forms/scolar/groups_form.py new file mode 100644 index 00000000..33a0d752 --- /dev/null +++ b/app/forms/scolar/groups_form.py @@ -0,0 +1,56 @@ +""" +Formulaire FlaskWTF pour les groupes +""" + +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, validators + + +class FeuilleAppelPreForm(FlaskForm): + """ + Formulaire utiliser dans le téléchargement des feuilles d'émargement + """ + + def __init__(self, *args, **kwargs): + "Init form, adding a filed for our error messages" + super().__init__(*args, **kwargs) + self.ok = True + self.error_messages: list[str] = [] + + def set_error(self, err_msg, field=None): + "Set error message both in form and field" + self.ok = False + self.error_messages.append(err_msg) + if field: + field.errors.append(err_msg) + + discipline = StringField( + "Discipline", + ) + + ens = StringField( + "Enseignant", + ) + + date = StringField( + "Date de la séance", + validators=[validators.Length(max=10)], + render_kw={ + "class": "datepicker", + "size": 10, + "id": "date", + }, + ) + + heure = StringField( + "Heure de début de la séance", + default="", + validators=[validators.Length(max=5)], + render_kw={ + "class": "timepicker", + "size": 5, + "id": "heure", + }, + ) + + submit = SubmitField("Télécharger la liste d'émargement") diff --git a/app/scodoc/sco_excel.py b/app/scodoc/sco_excel.py index 57dd86af..f82a04f9 100644 --- a/app/scodoc/sco_excel.py +++ b/app/scodoc/sco_excel.py @@ -26,8 +26,8 @@ ############################################################################## -""" Excel file handling -""" +"""Excel file handling""" + import datetime import io import time @@ -639,8 +639,23 @@ def excel_feuille_listeappel( with_codes=False, with_paiement=False, server_name=None, + edt_params: dict = None, ): - """generation feuille appel""" + """generation feuille appel + + edt_params : + - "discipline" : Discipline + - "ens" : Enseignant + - "date" : Date (format JJ/MM/AAAA) + - "heure" : Heure (format HH:MM) + """ + # Obligatoire sinon import circulaire + # pylint: disable=import-outside-toplevel + from app.scodoc.sco_groups import listgroups_abbrev, get_etud_groups + + if edt_params is None: + edt_params = {} + if partitions is None: partitions = [] formsemestre_id = sem["formsemestre_id"] @@ -648,8 +663,8 @@ def excel_feuille_listeappel( ws = ScoExcelSheet(sheet_name) ws.set_column_dimension_width("A", 3) - ws.set_column_dimension_width("B", 35) - ws.set_column_dimension_width("C", 12) + max_name_width: int = 35 + letter_int: int = ord("B") font1 = Font(name="Arial", size=11) font1i = Font(name="Arial", size=10, italic=True) @@ -675,11 +690,6 @@ def excel_feuille_listeappel( "font": Font(name="Arial", size=14), } - style2b = { - "font": font1i, - "border": border_tblr, - } - style2t3 = { "border": border_tblr, } @@ -693,8 +703,6 @@ def excel_feuille_listeappel( "font": Font(name="Arial", bold=True, size=14), } - nb_weeks = 4 # nombre de colonnes pour remplir absences - # ligne 1 title = "%s %s (%s - %s)" % ( sco_preferences.get_preference("DeptName", formsemestre_id), @@ -706,35 +714,67 @@ def excel_feuille_listeappel( ws.append_row([None, ws.make_cell(title, style2)]) # ligne 2 - ws.append_row([None, ws.make_cell("Discipline :", style2)]) + ws.append_row( + [ + None, + ws.make_cell("Discipline :", style2), + ws.make_cell(edt_params.get("discipline", ""), style3), + ] + ) # ligne 3 cell_2 = ws.make_cell("Enseignant :", style2) - cell_6 = ws.make_cell(f"Groupe {groupname}", style3) - ws.append_row([None, cell_2, None, None, None, None, cell_6]) + ws.append_row([None, cell_2, ws.make_cell(edt_params.get("ens", ""), style3)]) - # ligne 4: Avertissement pour ne pas confondre avec listes notes + # ligne 4: Avertissement pour ne pas confondre avec listes notes + Date + cell_1 = ws.make_cell("Date :", style2) cell_2 = ws.make_cell( "Ne pas utiliser cette feuille pour saisir les notes !", style1i ) - ws.append_row([None, None, cell_2]) + ws.append_row([None, cell_1, ws.make_cell(edt_params.get("date", ""))]) + + # ligne 5 : Heure + ws.append_row( + [ + None, + ws.make_cell("Heure :", style2), + ws.make_cell(edt_params.get("heure", "")), + ] + ) + + # ligne 6: groupe + ws.append_row([None, ws.make_cell(f"Groupe {groupname}", style3)]) ws.append_blank_row() - ws.append_blank_row() + ws.append_row([None, cell_2]) - # ligne 7: Entête (contruction dans une liste cells) + # ligne 9: Entête (contruction dans une liste cells) cell_2 = ws.make_cell("Nom", style3) cells = [None, cell_2] + letter_int += 1 + p_name: list = [] for partition in partitions: - cells.append(ws.make_cell(partition["partition_name"], style3)) + p_name.append(partition["partition_name"]) + + p_name: str = " / ".join(p_name) + ws.set_column_dimension_width(chr(letter_int), len(p_name)) if with_codes: cells.append(ws.make_cell("etudid", style3)) cells.append(ws.make_cell("code_nip", style3)) cells.append(ws.make_cell("code_ine", style3)) - for i in range(nb_weeks): - cells.append(ws.make_cell("", style2b)) + + # case Groupes + cells.append(ws.make_cell("Groupes", style3)) + letter_int += 1 + ws.set_column_dimension_width(chr(letter_int), 30) + + # case émargement + cells.append(ws.make_cell("Émargement", style3)) + letter_int += 1 + ws.set_column_dimension_width(chr(letter_int), 30) ws.append_row(cells) + row_id: int = len(ws.rows) + 1 n = 0 # pour chaque étudiant for t in lines: @@ -742,6 +782,8 @@ def excel_feuille_listeappel( nomprenom = ( t["civilite_str"] + " " + t["nom"] + " " + t["prenom"].lower().capitalize() ) + name_width = min(max_name_width, (len(nomprenom) + 2.0) * 1.25) + ws.set_column_dimension_width("B", name_width) style_nom = style2t3 if with_paiement: paie = t.get("paiementinscription", None) @@ -754,22 +796,19 @@ def excel_feuille_listeappel( cell_1 = ws.make_cell(n, style1b) cell_2 = ws.make_cell(nomprenom, style_nom) cells = [cell_1, cell_2] - - for partition in partitions: - if partition["partition_name"]: - cells.append( - ws.make_cell(t.get(partition["partition_id"], ""), style2t3) - ) + group = get_etud_groups(t["etudid"], formsemestre_id=formsemestre_id) + cells.append(ws.make_cell(listgroups_abbrev(group), style2t3)) if with_codes: cells.append(ws.make_cell(t["etudid"], style2t3)) code_nip = t.get("code_nip", "") cells.append(ws.make_cell(code_nip, style2t3)) code_ine = t.get("code_ine", "") cells.append(ws.make_cell(code_ine, style2t3)) - cells.append(ws.make_cell(t.get("etath", ""), style2b)) - for i in range(1, nb_weeks): - cells.append(ws.make_cell(style=style2t3)) + + cells.append(ws.make_cell(style=style2t3)) ws.append_row(cells) + ws.set_row_dimension_height(row_id, 30) + row_id += 1 ws.append_blank_row() diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 86d7db49..40ff6d7c 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -586,8 +586,8 @@ def groups_table( etud_info["_nom_disp_order"] = etud_sort_key(etud_info) etud_info["_prenom_target"] = fiche_url - etud_info["_nom_disp_td_attrs"] = 'id="%s" class="etudinfo"' % ( - etud_info["etudid"] + etud_info["_nom_disp_td_attrs"] = ( + 'id="%s" class="etudinfo"' % (etud_info["etudid"]) ) etud_info["bourse_str"] = "oui" if etud_info["boursier"] else "non" if etud_info["etat"] == "D": @@ -748,8 +748,6 @@ def groups_table( tab.html(), f"""