Ré-écriture de formation_list_table

This commit is contained in:
Emmanuel Viennet 2023-02-21 00:34:39 +01:00
parent 246fa62920
commit b924be56bb
2 changed files with 80 additions and 75 deletions

View File

@ -824,7 +824,8 @@ FORMATION_CURSUS_DESCRS = [p[1].__doc__ for p in _tp] # intitulés (eg pour men
FORMATION_CURSUS_TYPES = [p[0] for p in _tp] # codes numeriques (TYPE_CURSUS) FORMATION_CURSUS_TYPES = [p[0] for p in _tp] # codes numeriques (TYPE_CURSUS)
def get_cursus_from_code(code_cursus): def get_cursus_from_code(code_cursus: int) -> TypeCursus:
"renvoie le cursus de code indiqué"
cursus = SCO_CURSUS.get(code_cursus) cursus = SCO_CURSUS.get(code_cursus)
if cursus is None: if cursus is None:
log(f"Warning: invalid code_cursus: {code_cursus}") log(f"Warning: invalid code_cursus: {code_cursus}")

View File

@ -38,7 +38,7 @@ import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
from app import db from app import db
from app import log from app import log
from app.models import Formation, Module, UniteEns from app.models import Formation, FormSemestre, Module, UniteEns
from app.models import ScolarNews from app.models import ScolarNews
from app.models.but_refcomp import ( from app.models.but_refcomp import (
ApcAppCritique, ApcAppCritique,
@ -431,13 +431,12 @@ def formation_import_xml(doc: str, import_tags=True, use_local_refcomp=False):
return formation.id, modules_old2new, ues_old2new return formation.id, modules_old2new, ues_old2new
def formation_list_table(formation_id=None, args: dict = None): def formation_list_table() -> GenTable:
"""List formation, grouped by titre and sorted by versions """List formation, grouped by titre and sorted by versions
and listing associated semestres and listing associated semestres
returns a table returns a table
""" """
args = args or {} formations: list[Formation] = Formation.query.filter_by(dept_id=g.scodoc_dept_id)
formations = formation_list(formation_id=formation_id, args=args)
title = "Programmes pédagogiques" title = "Programmes pédagogiques"
lockicon = scu.icontag( lockicon = scu.icontag(
"lock32_img", title="Comporte des semestres verrouillés", border="0" "lock32_img", title="Comporte des semestres verrouillés", border="0"
@ -452,82 +451,89 @@ def formation_list_table(formation_id=None, args: dict = None):
editable = current_user.has_permission(Permission.ScoChangeFormation) editable = current_user.has_permission(Permission.ScoChangeFormation)
# Traduit/ajoute des champs à afficher: # Traduit/ajoute des champs à afficher:
for f in formations: rows = []
try: for formation in formations:
f["parcours_name"] = codes_cursus.get_cursus_from_code( acronyme_no_spaces = formation.acronyme.lower().replace(" ", "-")
f["type_parcours"] row = {
).NAME "acronyme": formation.acronyme,
except: "parcours_name": codes_cursus.get_cursus_from_code(
f["parcours_name"] = "" formation.type_parcours
f["_titre_target"] = url_for( ).NAME,
"notes.ue_table", "titre": formation.titre,
scodoc_dept=g.scodoc_dept, "_titre_target": url_for(
formation_id=str(f["formation_id"]), "notes.ue_table",
) scodoc_dept=g.scodoc_dept,
f["_titre_link_class"] = "stdlink" formation_id=formation.id,
f["_titre_id"] = "titre-%s" % f["acronyme"].lower().replace(" ", "-") ),
"_titre_link_class": "stdlink",
"_titre_id": f"""titre-{acronyme_no_spaces}""",
"version": formation.version or 0,
}
# Ajoute les semestres associés à chaque formation: # Ajoute les semestres associés à chaque formation:
f["sems"] = sco_formsemestre.do_formsemestre_list( row["formsemestres"] = formation.formsemestres.order_by(
args={"formation_id": f["formation_id"]} FormSemestre.date_debut
) ).all()
f["sems_list_txt"] = ", ".join([s["session_id"] for s in f["sems"]]) row["sems_list_txt"] = ", ".join(s.session_id() for s in row["formsemestres"])
f["_sems_list_txt_html"] = ", ".join( row["_sems_list_txt_html"] = (
[ ", ".join(
'<a class="discretelink" href="formsemestre_status?formsemestre_id=%(formsemestre_id)s">%(' f"""<a class="discretelink" href="{
"session_id)s<a> " % s url_for("notes.formsemestre_status",
for s in f["sems"] scodoc_dept=g.scodoc_dept, formsemestre_id=s.id
] )}">{s.session_id()}</a>
+ ( """
[ for s in row["formsemestres"]
'<a class="stdlink" id="add-semestre-%s" '
'href="formsemestre_createwithmodules?formation_id=%s&semestre_id=1">ajouter</a> '
% (f["acronyme"].lower().replace(" ", "-"), f["formation_id"])
]
if current_user.has_permission(Permission.ScoImplement)
else []
) )
+ f""", <a class="stdlink" id="add-semestre-{
formation.acronyme.lower().replace(" ", "-")}"
href={ url_for("notes.formsemestre_createwithmodules",
scodoc_dept=g.scodoc_dept, formation_id=formation.id, semestre_id=1
)
}">ajouter</a>
"""
) )
if f["sems"]: if row["formsemestres"]:
f["date_fin_dernier_sem"] = max([s["date_fin_iso"] for s in f["sems"]]) row["date_fin_dernier_sem"] = (
f["annee_dernier_sem"] = f["date_fin_dernier_sem"].split("-")[0] row["formsemestres"][-1].date_fin.isoformat(),
)
row["annee_dernier_sem"] = row["formsemestres"][-1].date_fin.year
else: else:
f["date_fin_dernier_sem"] = "" row["date_fin_dernier_sem"] = ""
f["annee_dernier_sem"] = "" row["annee_dernier_sem"] = 0
formation: Formation = Formation.query.get_or_404(f["formation_id"])
locked = formation.has_locked_sems()
# #
if locked: if formation.has_locked_sems():
but_locked = lockicon but_locked = lockicon
but_suppr = '<span class="but_placeholder"></span>'
else: else:
but_locked = '<span class="but_placeholder"></span>' but_locked = '<span class="but_placeholder"></span>'
if editable and not locked: if editable:
but_suppr = ( but_suppr = f"""<a class="stdlink" href="{
'<a class="stdlink" href="formation_delete?formation_id=%s" id="delete-formation-%s">%s</a>' url_for("notes.formation_delete",
% ( scodoc_dept=g.scodoc_dept, formation_id=formation.id
f["formation_id"], )}" id="delete-formation-{acronyme_no_spaces}">{suppricon}</a>"""
f["acronyme"].lower().replace(" ", "-"), else:
suppricon, but_suppr = '<span class="but_placeholder"></span>'
)
)
else:
but_suppr = '<span class="but_placeholder"></span>'
if editable: if editable:
but_edit = ( but_edit = f"""<a class="stdlink" href="{
'<a class="stdlink" href="formation_edit?formation_id=%s" id="edit-formation-%s">%s</a>' url_for("notes.formation_edit", scodoc_dept=g.scodoc_dept, formation_id=formation.id)
% (f["formation_id"], f["acronyme"].lower().replace(" ", "-"), editicon) }" id="edit-formation-{acronyme_no_spaces}">{editicon}</a>"""
)
else: else:
but_edit = '<span class="but_placeholder"></span>' but_edit = '<span class="but_placeholder"></span>'
f["buttons"] = "" row["buttons"] = ""
f["_buttons_html"] = but_locked + but_suppr + but_edit row["_buttons_html"] = but_locked + but_suppr + but_edit
# Tri par annee_denier_sem, type, acronyme, titre, version décroissante rows.append(row)
formations.sort(key=itemgetter("version"), reverse=True) # Tri par annee_dernier_sem, type, acronyme, titre, version décroissante
formations.sort(key=itemgetter("titre")) # donc plus récemment utilsiée en tête
formations.sort(key=itemgetter("acronyme")) rows.sort(
formations.sort(key=itemgetter("parcours_name")) key=lambda row: (
formations.sort( -row["annee_dernier_sem"],
key=itemgetter("annee_dernier_sem"), reverse=True row["parcours_name"],
) # plus recemments utilises en tete row["acronyme"],
row["titre"],
-row["version"],
)
)
for i, row in enumerate(rows):
row["_buttons_order"] = f"{i:05d}"
# #
columns_ids = ( columns_ids = (
@ -550,18 +556,16 @@ def formation_list_table(formation_id=None, args: dict = None):
} }
return GenTable( return GenTable(
columns_ids=columns_ids, columns_ids=columns_ids,
rows=formations, rows=rows,
titles=titles, titles=titles,
origin="Généré par %s le " % sco_version.SCONAME origin=f"Généré par {sco_version.SCONAME} le {scu.timedate_human_repr()}",
+ scu.timedate_human_repr()
+ "",
caption=title, caption=title,
html_caption=title, html_caption=title,
table_id="formation_list_table", table_id="formation_list_table",
html_class="formation_list_table table_leftalign", html_class="formation_list_table table_leftalign",
html_with_td_classes=True, html_with_td_classes=True,
html_sortable=True, html_sortable=True,
base_url="%s?formation_id=%s" % (request.base_url, formation_id), base_url="{request.base_url}?formation_id={formation_id}",
page_title=title, page_title=title,
pdf_title=title, pdf_title=title,
preferences=sco_preferences.SemPreferences(), preferences=sco_preferences.SemPreferences(),