Update opolka/ScoDoc from ScoDoc/ScoDoc #2

Merged
opolka merged 1272 commits from ScoDoc/ScoDoc:master into master 2024-05-27 09:11:04 +02:00
3 changed files with 107 additions and 41 deletions
Showing only changes of commit 29eb8c297b - Show all commits

View File

@ -46,10 +46,10 @@ from app.scodoc import sco_users
from app.views import ScoData 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)" "Page accueil département (liste des semestres)"
showcodes = int(showcodes) 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 # Liste tous les formsemestres du dept, le plus récent d'abord
current_formsemestres = ( current_formsemestres = (
@ -68,9 +68,14 @@ def index_html(showcodes=0, showsemtable=0):
.order_by(desc(FormSemestre.date_debut)) .order_by(desc(FormSemestre.date_debut))
) )
if showsemtable: # table de tous les formsemestres if showsemtable: # table de tous les formsemestres
html_table_formsemestres = _sem_table_gt( table = _sem_table_gt(
formsemestres, showcodes=showcodes formsemestres,
).html() 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: else:
html_table_formsemestres = None html_table_formsemestres = None
@ -95,26 +100,40 @@ def index_html(showcodes=0, showsemtable=0):
def _convert_formsemestres_to_dicts( def _convert_formsemestres_to_dicts(
formsemestres: Query, showcodes: bool formsemestres: Query, showcodes: bool, fmt: str = "html"
) -> list[dict]: ) -> list[dict]:
""" """ """ """
# icon image: if fmt == "html":
# icon images:
groupicon = scu.icontag("groupicon_img", title="Inscrits", border="0") groupicon = scu.icontag("groupicon_img", title="Inscrits", border="0")
emptygroupicon = scu.icontag( emptygroupicon = scu.icontag(
"emptygroupicon_img", title="Pas d'inscrits", border="0" "emptygroupicon_img", title="Pas d'inscrits", border="0"
) )
lockicon = scu.icontag("lock32_img", title="verrouillé", border="0") lockicon = scu.icontag("lock32_img", title="verrouillé", border="0")
else:
groupicon = "X"
emptygroupicon = ""
lockicon = "X"
# génère liste de dict # génère liste de dict
sems = [] sems = []
for formsemestre in formsemestres: for formsemestre in formsemestres:
nb_inscrits = len(formsemestre.inscriptions) nb_inscrits = len(formsemestre.inscriptions)
formation = formsemestre.formation
sem = { sem = {
"anneescolaire": formsemestre.annee_scolaire(), "anneescolaire": formsemestre.annee_scolaire(),
"anneescolaire_str": formsemestre.annee_scolaire_str(),
"bul_hide_xml": formsemestre.bul_hide_xml, "bul_hide_xml": formsemestre.bul_hide_xml,
"dateord": formsemestre.date_debut, "dateord": formsemestre.date_debut,
"elt_annee_apo": formsemestre.elt_annee_apo, "elt_annee_apo": formsemestre.elt_annee_apo,
"elt_sem_apo": formsemestre.elt_sem_apo, "elt_sem_apo": formsemestre.elt_sem_apo,
"etapes_apo_str": formsemestre.etapes_apo_str(), "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, "formsemestre_id": formsemestre.id,
"groupicon": groupicon if nb_inscrits > 0 else emptygroupicon, "groupicon": groupicon if nb_inscrits > 0 else emptygroupicon,
"lockimg": lockicon, "lockimg": lockicon,
@ -126,9 +145,7 @@ def _convert_formsemestres_to_dicts(
"semestre_id": formsemestre.semestre_id, "semestre_id": formsemestre.semestre_id,
"session_id": formsemestre.session_id(), "session_id": formsemestre.session_id(),
"titre_num": formsemestre.titre_num(), "titre_num": formsemestre.titre_num(),
"tmpcode": ( "tmpcode": (f"<td><tt>{formsemestre.id}</tt></td>" if showcodes else ""),
f"<td><tt>{sem['formsemestre_id']}</tt></td>" if showcodes else ""
),
} }
sems.append(sem) sems.append(sem)
return sems return sems
@ -189,11 +206,13 @@ def _sem_table(sems: list[dict]) -> str:
return "\n".join(H) 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 """Table des semestres
Utilise une datatables. 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( sems.sort(
key=lambda s: ( key=lambda s: (
-s["anneescolaire"], -s["anneescolaire"],
@ -206,10 +225,10 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable:
"published", "published",
"semestre_id_n", "semestre_id_n",
"modalite", "modalite",
#'mois_debut',
"dash_mois_fin", "dash_mois_fin",
"titre_resp", "titre_resp",
"nb_inscrits", "nb_inscrits",
"formation",
"etapes_apo_str", "etapes_apo_str",
"elt_annee_apo", "elt_annee_apo",
"elt_sem_apo", "elt_sem_apo",
@ -224,7 +243,7 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable:
titles={ titles={
"formsemestre_id": "id", "formsemestre_id": "id",
"semestre_id_n": "S#", "semestre_id_n": "S#",
"modalite": "", "modalite": "" if fmt == "html" else "Modalité",
"mois_debut": "Début", "mois_debut": "Début",
"dash_mois_fin": "Année", "dash_mois_fin": "Année",
"titre_resp": "Semestre", "titre_resp": "Semestre",
@ -232,6 +251,7 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable:
"etapes_apo_str": "Étape Apo.", "etapes_apo_str": "Étape Apo.",
"elt_annee_apo": "Elt. année Apo.", "elt_annee_apo": "Elt. année Apo.",
"elt_sem_apo": "Elt. sem. Apo.", "elt_sem_apo": "Elt. sem. Apo.",
"formation": "Formation",
}, },
columns_ids=columns_ids, columns_ids=columns_ids,
rows=sems, rows=sems,
@ -251,8 +271,23 @@ def _sem_table_gt(formsemestres: Query, showcodes=False) -> GenTable:
return tab 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""" """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: for sem in sems:
status_url = url_for( status_url = url_for(
"notes.formsemestre_status", "notes.formsemestre_status",
@ -261,24 +296,21 @@ def _style_sems(sems: list[dict]) -> list[dict]:
) )
sem["_groupicon_target"] = status_url sem["_groupicon_target"] = status_url
sem["_formsemestre_id_class"] = "blacktt" sem["_formsemestre_id_class"] = "blacktt"
sem["dash_mois_fin"] = '<a title="%(session_id)s"></a> %(anneescolaire)s' % sem sem["dash_mois_fin"] = (
(f"""<a title="{sem['session_id']}">{sem['anneescolaire_str']}</a>""")
if is_h
else sem["anneescolaire_str"]
)
sem["_dash_mois_fin_class"] = "datesem" sem["_dash_mois_fin_class"] = "datesem"
sem["titre_resp"] = ( sem["titre_resp"] = (
f"""<a class="stdlink" href="{status_url}">{sem['titre_num']}</a> <span class="respsem">({sem['responsable_name']})</span>""" (
) f"""<a class="stdlink" href="{status_url}">{sem['titre_num']}</a>
sem["published"] = ( <span class="respsem">({sem['responsable_name']})</span>"""
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",
) )
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["_css_row_class"] = "css_S%d css_M%s" % (
sem["semestre_id"], sem["semestre_id"],

View File

@ -4,14 +4,30 @@
{% block app_content %} {% block app_content %}
<style> <style>
td.datesem {
font-size: 80%; table.listesems tr td.datesem {
white-space: nowrap; white-space: nowrap;
padding-left: 8px; padding-left: 8px;
} }
td.titresem { table.listesems tr td.titresem {
padding-left: 6px; padding-left: 6px;
} }
.table-formsemestres-titre {
font-weight: bold;
font-size: 110%;
}
table.semlist tr td.datesem {
font-size: 80%;
text-align: center;
}
table.semlist tr td.semestre_id_n {
text-align: center;
}
table.semlist tr td.nb_inscrits {
text-align: center;
}
</style> </style>
{# News #} {# News #}
@ -39,8 +55,12 @@ td.titresem {
{% if html_table_formsemestres %} {% if html_table_formsemestres %}
<details open> <details open>
<summary> <summary class="table-formsemestres-titre">
Semestres de {{dept_name}} Les {{formsemestres.count()}} semestres de {{dept_name}}
&nbsp;
<a href="{{
url_for('scolar.export_table_dept_formsemestres', scodoc_dept=g.scodoc_dept)
}}">{{scu.ICON_XLS|safe}}</a>
</summary> </summary>
{{ html_table_formsemestres|safe }} {{ html_table_formsemestres|safe }}
</details> </details>

View File

@ -349,6 +349,20 @@ def index_html(showcodes=0, showsemtable=0):
return sco_dept.index_html(showcodes=showcodes, showsemtable=showsemtable) 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") @bp.route("/install_info")
@scodoc @scodoc
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)