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
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"<td><tt>{sem['formsemestre_id']}</tt></td>" if showcodes else ""
),
"tmpcode": (f"<td><tt>{formsemestre.id}</tt></td>" 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"] = '<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["titre_resp"] = (
f"""<a class="stdlink" href="{status_url}">{sem['titre_num']}</a> <span class="respsem">({sem['responsable_name']})</span>"""
)
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"""<a class="stdlink" href="{status_url}">{sem['titre_num']}</a>
<span class="respsem">({sem['responsable_name']})</span>"""
)
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"],

View File

@ -4,14 +4,30 @@
{% block app_content %}
<style>
td.datesem {
font-size: 80%;
white-space: nowrap;
padding-left: 8px;
table.listesems tr td.datesem {
white-space: nowrap;
padding-left: 8px;
}
td.titresem {
table.listesems tr td.titresem {
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>
{# News #}
@ -39,8 +55,12 @@ td.titresem {
{% if html_table_formsemestres %}
<details open>
<summary>
Semestres de {{dept_name}}
<summary class="table-formsemestres-titre">
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>
{{ html_table_formsemestres|safe }}
</details>

View File

@ -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)