fix: het sort

This commit is contained in:
Emmanuel Viennet 2022-01-05 01:03:25 +01:00
parent 5895e5c33c
commit 4b63fe81e4
2 changed files with 12 additions and 11 deletions

View File

@ -49,16 +49,12 @@ from app.scodoc import sco_etud
from app.scodoc import sco_excel from app.scodoc import sco_excel
from app.scodoc import sco_formsemestre from app.scodoc import sco_formsemestre
from app.scodoc import sco_formsemestre_inscriptions from app.scodoc import sco_formsemestre_inscriptions
from app.scodoc import sco_formsemestre_status
from app.scodoc import sco_parcours_dut from app.scodoc import sco_parcours_dut
from app.scodoc import sco_pdf
from app.scodoc import sco_preferences from app.scodoc import sco_preferences
import sco_version import sco_version
from app.scodoc.gen_tables import GenTable from app.scodoc.gen_tables import GenTable
from app import log from app import log
from app.scodoc.sco_codes_parcours import code_semestre_validant from app.scodoc.sco_codes_parcours import code_semestre_validant
from app.scodoc.sco_exceptions import ScoValueError
from app.scodoc.sco_pdf import SU
MAX_ETUD_IN_DESCR = 20 MAX_ETUD_IN_DESCR = 20
@ -121,9 +117,9 @@ def _categories_and_results(etuds, category, result):
categories[etud[category]] = True categories[etud[category]] = True
results[etud[result]] = True results[etud[result]] = True
categories = list(categories.keys()) categories = list(categories.keys())
categories.sort() categories.sort(key=scu.heterogeneous_sorting_key)
results = list(results.keys()) results = list(results.keys())
results.sort() results.sort(key=scu.heterogeneous_sorting_key)
return categories, results return categories, results
@ -166,7 +162,7 @@ def _results_by_category(
l["sumpercent"] = "%2.1f%%" % ((100.0 * l["sum"]) / tot) l["sumpercent"] = "%2.1f%%" % ((100.0 * l["sum"]) / tot)
# #
codes = list(results.keys()) codes = list(results.keys())
codes.sort() codes.sort(key=scu.heterogeneous_sorting_key)
bottom_titles = [] bottom_titles = []
if C: # ligne du bas avec totaux: if C: # ligne du bas avec totaux:
@ -314,7 +310,7 @@ def formsemestre_report_counts(
"type_admission", "type_admission",
"boursier_prec", "boursier_prec",
] ]
keys.sort() keys.sort(key=scu.heterogeneous_sorting_key)
F = [ F = [
"""<form name="f" method="get" action="%s"><p> """<form name="f" method="get" action="%s"><p>
Colonnes: <select name="result" onchange="document.f.submit()">""" Colonnes: <select name="result" onchange="document.f.submit()">"""
@ -497,7 +493,7 @@ def table_suivi_cohorte(
P.append(p) P.append(p)
# 4-- regroupe par indice de semestre S_i # 4-- regroupe par indice de semestre S_i
indices_sems = list(set([s["semestre_id"] for s in sems])) indices_sems = list({s["semestre_id"] for s in sems})
indices_sems.sort() indices_sems.sort()
for p in P: for p in P:
p.nb_etuds = 0 # nombre total d'etudiants dans la periode p.nb_etuds = 0 # nombre total d'etudiants dans la periode
@ -788,9 +784,9 @@ def _gen_form_selectetuds(
): ):
"""HTML form pour choix criteres selection etudiants""" """HTML form pour choix criteres selection etudiants"""
bacs = list(bacs) bacs = list(bacs)
bacs.sort() bacs.sort(key=scu.heterogeneous_sorting_key)
bacspecialites = list(bacspecialites) bacspecialites = list(bacspecialites)
bacspecialites.sort() bacspecialites.sort(key=scu.heterogeneous_sorting_key)
# on peut avoir un mix de chaines vides et d'entiers: # on peut avoir un mix de chaines vides et d'entiers:
annee_bacs = [int(x) if x else 0 for x in annee_bacs] annee_bacs = [int(x) if x else 0 for x in annee_bacs]
annee_bacs.sort() annee_bacs.sort()

View File

@ -898,6 +898,11 @@ def sort_dates(L, reverse=False):
raise raise
def heterogeneous_sorting_key(x):
"key to sort non homogeneous sequences"
return (float(x), "") if isinstance(x, (bool, float, int)) else (-1e34, str(x))
def query_portal(req, msg="Portail Apogee", timeout=3): def query_portal(req, msg="Portail Apogee", timeout=3):
"""Retreives external data using HTTP request """Retreives external data using HTTP request
(used to connect to Apogee portal, or ScoDoc server) (used to connect to Apogee portal, or ScoDoc server)