1
0
forked from ScoDoc/ScoDoc

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