From 29eb8c297b0b2dc4ad41e28c5d3da7d58a0f8662 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 21 Mar 2024 13:21:16 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20page=20accueil=20dept.:=20forma?= =?UTF-8?q?tion,=20cosm=C3=A9tique,=20export=20excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_dept.py | 100 ++++++++++++++++++++++------------ app/templates/scolar/index.j2 | 34 +++++++++--- app/views/scolar.py | 14 +++++ 3 files changed, 107 insertions(+), 41 deletions(-) diff --git a/app/scodoc/sco_dept.py b/app/scodoc/sco_dept.py index 97fce15c..9f861de8 100644 --- a/app/scodoc/sco_dept.py +++ b/app/scodoc/sco_dept.py @@ -46,10 +46,10 @@ from app.scodoc import sco_users from app.views import ScoData -def index_html(showcodes=0, showsemtable=0): +def index_html(showcodes=0, showsemtable=0, export_table_formsemestres=False): "Page accueil département (liste des semestres)" showcodes = int(showcodes) - showsemtable = int(showsemtable) + showsemtable = int(showsemtable) or export_table_formsemestres # Liste tous les formsemestres du dept, le plus récent d'abord current_formsemestres = ( @@ -68,9 +68,14 @@ def index_html(showcodes=0, showsemtable=0): .order_by(desc(FormSemestre.date_debut)) ) if showsemtable: # table de tous les formsemestres - html_table_formsemestres = _sem_table_gt( - formsemestres, showcodes=showcodes - ).html() + table = _sem_table_gt( + formsemestres, + showcodes=showcodes, + fmt="xlsx" if export_table_formsemestres else "html", + ) + if export_table_formsemestres: + return table # cas spécial: on renvoie juste cette table + html_table_formsemestres = table.html() else: html_table_formsemestres = None @@ -95,26 +100,40 @@ def index_html(showcodes=0, showsemtable=0): def _convert_formsemestres_to_dicts( - formsemestres: Query, showcodes: bool + formsemestres: Query, showcodes: bool, fmt: str = "html" ) -> list[dict]: """ """ - # icon image: - groupicon = scu.icontag("groupicon_img", title="Inscrits", border="0") - emptygroupicon = scu.icontag( - "emptygroupicon_img", title="Pas d'inscrits", border="0" - ) - lockicon = scu.icontag("lock32_img", title="verrouillé", border="0") + if fmt == "html": + # icon images: + groupicon = scu.icontag("groupicon_img", title="Inscrits", border="0") + emptygroupicon = scu.icontag( + "emptygroupicon_img", title="Pas d'inscrits", border="0" + ) + lockicon = scu.icontag("lock32_img", title="verrouillé", border="0") + else: + groupicon = "X" + emptygroupicon = "" + lockicon = "X" # génère liste de dict sems = [] for formsemestre in formsemestres: nb_inscrits = len(formsemestre.inscriptions) + formation = formsemestre.formation sem = { "anneescolaire": formsemestre.annee_scolaire(), + "anneescolaire_str": formsemestre.annee_scolaire_str(), "bul_hide_xml": formsemestre.bul_hide_xml, "dateord": formsemestre.date_debut, "elt_annee_apo": formsemestre.elt_annee_apo, "elt_sem_apo": formsemestre.elt_sem_apo, "etapes_apo_str": formsemestre.etapes_apo_str(), + "formation": f"{formation.acronyme} v{formation.version}", + "_formation_target": url_for( + "notes.ue_table", + scodoc_dept=g.scodoc_dept, + formation_id=formation.id, + semestre_idx=formsemestre.semestre_id, + ), "formsemestre_id": formsemestre.id, "groupicon": groupicon if nb_inscrits > 0 else emptygroupicon, "lockimg": lockicon, @@ -126,9 +145,7 @@ def _convert_formsemestres_to_dicts( "semestre_id": formsemestre.semestre_id, "session_id": formsemestre.session_id(), "titre_num": formsemestre.titre_num(), - "tmpcode": ( - f"{sem['formsemestre_id']}" if showcodes else "" - ), + "tmpcode": (f"{formsemestre.id}" if showcodes else ""), } sems.append(sem) return sems @@ -189,11 +206,13 @@ def _sem_table(sems: list[dict]) -> str: return "\n".join(H) -def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable: +def _sem_table_gt(formsemestres: Query, showcodes=False, fmt="html") -> GenTable: """Table des semestres Utilise une datatables. """ - sems = _style_sems(_convert_formsemestres_to_dicts(formsemestres, showcodes)) + sems = _style_sems( + _convert_formsemestres_to_dicts(formsemestres, showcodes, fmt=fmt), fmt=fmt + ) sems.sort( key=lambda s: ( -s["anneescolaire"], @@ -206,10 +225,10 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable: "published", "semestre_id_n", "modalite", - #'mois_debut', "dash_mois_fin", "titre_resp", "nb_inscrits", + "formation", "etapes_apo_str", "elt_annee_apo", "elt_sem_apo", @@ -224,7 +243,7 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable: titles={ "formsemestre_id": "id", "semestre_id_n": "S#", - "modalite": "", + "modalite": "" if fmt == "html" else "Modalité", "mois_debut": "Début", "dash_mois_fin": "Année", "titre_resp": "Semestre", @@ -232,6 +251,7 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable: "etapes_apo_str": "Étape Apo.", "elt_annee_apo": "Elt. année Apo.", "elt_sem_apo": "Elt. sem. Apo.", + "formation": "Formation", }, columns_ids=columns_ids, rows=sems, @@ -251,8 +271,23 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable: return tab -def _style_sems(sems: list[dict]) -> list[dict]: +def _style_sems(sems: list[dict], fmt="html") -> list[dict]: """ajoute quelques attributs de présentation pour la table""" + is_h = fmt == "html" + if is_h: + icon_published = scu.icontag( + "eye_img", + border="0", + title="Bulletins publiés sur la passerelle étudiants", + ) + icon_hidden = scu.icontag( + "hide_img", + border="0", + title="Bulletins NON publiés sur la passerelle étudiants", + ) + else: + icon_published = "publié" + icon_hidden = "non publié" for sem in sems: status_url = url_for( "notes.formsemestre_status", @@ -261,24 +296,21 @@ def _style_sems(sems: list[dict]) -> list[dict]: ) sem["_groupicon_target"] = status_url sem["_formsemestre_id_class"] = "blacktt" - sem["dash_mois_fin"] = ' %(anneescolaire)s' % sem + sem["dash_mois_fin"] = ( + (f"""{sem['anneescolaire_str']}""") + if is_h + else sem["anneescolaire_str"] + ) sem["_dash_mois_fin_class"] = "datesem" sem["titre_resp"] = ( - f"""{sem['titre_num']} ({sem['responsable_name']})""" - ) - sem["published"] = ( - scu.icontag( - "hide_img", - border="0", - title="Bulletins NON publiés sur la passerelle étudiants", - ) - if sem["bul_hide_xml"] - else scu.icontag( - "eye_img", - border="0", - title="Bulletins publiés sur la passerelle étudiants", + ( + f"""{sem['titre_num']} + ({sem['responsable_name']})""" ) + if is_h + else f"""{sem['titre_num']} ({sem["responsable_name"]})""" ) + sem["published"] = icon_hidden if sem["bul_hide_xml"] else icon_published sem["_css_row_class"] = "css_S%d css_M%s" % ( sem["semestre_id"], diff --git a/app/templates/scolar/index.j2 b/app/templates/scolar/index.j2 index 09c3e9de..0ca69fcc 100644 --- a/app/templates/scolar/index.j2 +++ b/app/templates/scolar/index.j2 @@ -4,14 +4,30 @@ {% block app_content %} {# News #} @@ -39,8 +55,12 @@ td.titresem { {% if html_table_formsemestres %}
- - Semestres de {{dept_name}} + + Les {{formsemestres.count()}} semestres de {{dept_name}} +   + {{scu.ICON_XLS|safe}} {{ html_table_formsemestres|safe }}
diff --git a/app/views/scolar.py b/app/views/scolar.py index f3025ddb..f20e24c5 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -349,6 +349,20 @@ def index_html(showcodes=0, showsemtable=0): return sco_dept.index_html(showcodes=showcodes, showsemtable=showsemtable) +@bp.route("/export_table_dept_formsemestres") +@scodoc +@permission_required(Permission.ScoView) +def export_table_dept_formsemestres(): + """La table de tous les semestres non EXt du département, en excel""" + table = sco_dept.index_html(showcodes=True, export_table_formsemestres=True) + return scu.send_file( + table.excel(), + f"semestres_{g.scodoc_dept}", + suffix=scu.XLSX_SUFFIX, + mime=scu.XLSX_MIMETYPE, + ) + + @bp.route("/install_info") @scodoc @permission_required(Permission.ScoView)