sort: removed cmp argument
This commit is contained in:
parent
aea498fa86
commit
510e6dc9c7
@ -31,6 +31,7 @@ from types import StringType, FloatType
|
||||
import time
|
||||
import pdb
|
||||
import inspect
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
import app.scodoc.notesdb as ndb
|
||||
@ -207,7 +208,7 @@ class NotesTable:
|
||||
x["nomp"] = (i["nom_usuel"] or i["nom"]) + i["prenom"] # pour tri
|
||||
|
||||
# Tri les etudids par NOM
|
||||
self.inscrlist.sort(lambda x, y: cmp(x["nomp"], y["nomp"]))
|
||||
self.inscrlist.sort(key=itemgetter("nomp"))
|
||||
|
||||
# { etudid : rang dans l'ordre alphabetique }
|
||||
rangalpha = {}
|
||||
@ -306,33 +307,18 @@ class NotesTable:
|
||||
T.append(tuple(t))
|
||||
# tri par moyennes décroissantes,
|
||||
# en laissant les demissionnaires a la fin, par ordre alphabetique
|
||||
def cmprows(x, y):
|
||||
def row_key(x):
|
||||
"""clé de tri par moyennes décroissantes,
|
||||
en laissant les demissionnaires a la fin, par ordre alphabetique.
|
||||
(moy_gen, rang_alpha)
|
||||
"""
|
||||
try:
|
||||
return cmp(float(y[0]), float(x[0])) # moy. gen.
|
||||
except:
|
||||
vx, vy = x[0], y[0]
|
||||
try:
|
||||
vx = float(vx)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
vy = float(vy)
|
||||
except:
|
||||
pass
|
||||
moy = -float(x[0])
|
||||
except (ValueError, TypeError):
|
||||
moy = 1000.0
|
||||
return (moy, rangalpha[x[-1]])
|
||||
|
||||
if type(vx) == type(vy): # and type(vx) == StringType:
|
||||
# rang alphabetique par nom
|
||||
return rangalpha[x[-1]] - rangalpha[y[-1]]
|
||||
else:
|
||||
# Laisse les chaines a la fin de la liste
|
||||
return cmp(str(type(vx)), str(type(vy))) # A revoir !
|
||||
# fallback *** should not occur ***
|
||||
# txt = '\nkey missing in cmprows !!!\nx=%s\ny=%s\n' % (str(x),str(y))
|
||||
# txt += '\nrangalpha=%s' % str(rangalpha) + '\n\nT=%s' % str(T)
|
||||
# send_debug_alert(txt, REQUEST=None)
|
||||
# return cmp(x,y)
|
||||
|
||||
T.sort(cmprows)
|
||||
T.sort(key=row_key)
|
||||
self.T = T
|
||||
|
||||
if len(valid_moy):
|
||||
@ -363,7 +349,7 @@ class NotesTable:
|
||||
ue_eff = len(
|
||||
[x for x in val_ids if type(x[0]) == FloatType]
|
||||
) # nombre d'étudiants avec une note dans l'UE
|
||||
val_ids.sort(cmprows)
|
||||
val_ids.sort(key=row_key)
|
||||
ue_rangs[ue_id] = (
|
||||
comp_ranks(val_ids),
|
||||
ue_eff,
|
||||
@ -374,7 +360,7 @@ class NotesTable:
|
||||
for modimpl in self._modimpls:
|
||||
vals = self._modmoys[modimpl["moduleimpl_id"]]
|
||||
val_ids = [(vals[etudid], etudid) for etudid in vals.keys()]
|
||||
val_ids.sort(cmprows)
|
||||
val_ids.sort(key=row_key)
|
||||
self.mod_rangs[modimpl["moduleimpl_id"]] = (comp_ranks(val_ids), len(vals))
|
||||
#
|
||||
self.compute_moy_moy()
|
||||
@ -483,14 +469,7 @@ class NotesTable:
|
||||
r = [m for m in self._modimpls if m["ue"]["ue_id"] == ue_id]
|
||||
# trie la liste par ue.numero puis mat.numero puis mod.numero
|
||||
r.sort(
|
||||
lambda x, y: cmp(
|
||||
x["ue"]["numero"] * 1000000
|
||||
+ x["mat"]["numero"] * 1000
|
||||
+ x["module"]["numero"],
|
||||
y["ue"]["numero"] * 1000000
|
||||
+ y["mat"]["numero"] * 1000
|
||||
+ y["module"]["numero"],
|
||||
)
|
||||
key=lambda x: (x["ue"]["numero"], x["mat"]["numero"], x["module"]["numero"])
|
||||
)
|
||||
return r
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
"""
|
||||
# codes anciens déplacés de ZEntreprise
|
||||
import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
import app.scodoc.notesdb as ndb
|
||||
@ -94,7 +95,7 @@ class EntreprisesEditor(EditableTable):
|
||||
else:
|
||||
r["date"] = datetime.date.min
|
||||
# sort
|
||||
R.sort(lambda r1, r2: cmp(r2["date"], r1["date"]))
|
||||
R.sort(key=itemgetter("date"))
|
||||
for r in R:
|
||||
r["date"] = DateISOtoDMY(r["date"])
|
||||
return R
|
||||
@ -122,11 +123,8 @@ class EntreprisesEditor(EditableTable):
|
||||
R.append(d)
|
||||
# sort
|
||||
if sort_on_contact:
|
||||
R.sort(
|
||||
lambda r1, r2: cmp(
|
||||
r2["date"] or datetime.date.min, r1["date"] or datetime.date.min
|
||||
)
|
||||
)
|
||||
R.sort(key=lambda x: (x["date"] or datetime.date.min))
|
||||
|
||||
for r in R:
|
||||
r["date"] = DateISOtoDMY(r["date"] or datetime.date.min)
|
||||
return R
|
||||
|
@ -36,6 +36,7 @@ from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.header import Header
|
||||
from email.mime.base import MIMEBase
|
||||
from operator import itemgetter
|
||||
|
||||
from app.scodoc import sco_emails
|
||||
import app.scodoc.sco_utils as scu
|
||||
@ -605,7 +606,7 @@ class EtudIdentEditor:
|
||||
}
|
||||
res[-1].update(void_adm)
|
||||
# tri par nom
|
||||
res.sort(lambda x, y: cmp(x["nom"] + x["prenom"], y["nom"] + y["prenom"]))
|
||||
res.sort(key=itemgetter("nom", "prenom"))
|
||||
return res
|
||||
|
||||
def edit(self, cnx, args, context=None, REQUEST=None):
|
||||
@ -937,7 +938,7 @@ def fill_etuds_info(etuds):
|
||||
sems.append(sem)
|
||||
# trie les semestres par date de debut, le plus recent d'abord
|
||||
# (important, ne pas changer (suivi cohortes))
|
||||
sems.sort(lambda x, y: cmp(y["dateord"], x["dateord"]))
|
||||
sems.sort(key=itemgetter("dateord"), reverse=True)
|
||||
etud["sems"] = sems
|
||||
etud["cursem"] = cursem
|
||||
if cursem:
|
||||
|
@ -28,6 +28,7 @@
|
||||
"""Operations de base sur les formsemestres
|
||||
"""
|
||||
import time
|
||||
from operator import itemgetter
|
||||
|
||||
from scodoc_manager import sco_mgr
|
||||
from app.scodoc import sco_codes_parcours
|
||||
@ -118,12 +119,8 @@ def do_formsemestre_list(context, *a, **kw):
|
||||
for sem in sems:
|
||||
formsemestre_enrich(context, sem)
|
||||
|
||||
# tri par date
|
||||
sems.sort(
|
||||
lambda x, y: cmp(
|
||||
(y["dateord"], y["semestre_id"]), (x["dateord"], x["semestre_id"])
|
||||
)
|
||||
)
|
||||
# tri par date, le plus récent d'abord
|
||||
sems.sort(key=itemgetter("dateord", "semestre_id"), reverse=True)
|
||||
|
||||
return sems
|
||||
|
||||
|
@ -33,6 +33,16 @@ from types import FloatType, IntType, LongType, StringType
|
||||
from functools import reduce
|
||||
|
||||
|
||||
def cmp(x, y):
|
||||
"""
|
||||
Replacement for built-in function cmp that was removed in Python 3
|
||||
Compare the two objects x and y and return an integer according to
|
||||
the outcome. The return value is negative if x < y, zero if x == y
|
||||
and strictly positive if x > y.
|
||||
"""
|
||||
return (x > y) - (x < y)
|
||||
|
||||
|
||||
class NoteVector(object):
|
||||
"""Vecteur de notes (ou coefficients) utilisé pour les formules définies par l'utilisateur.
|
||||
Les éléments sont accessibles soit par index v[i], soit par leur nom v['nom'] s'il en ont un.
|
||||
|
@ -29,6 +29,7 @@
|
||||
Utilise les autorisations d'inscription délivrées en jury.
|
||||
"""
|
||||
import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.notesdb as ndb
|
||||
import app.scodoc.sco_utils as scu
|
||||
@ -301,7 +302,7 @@ def formsemestre_inscr_passage(
|
||||
|
||||
def set_to_sorted_etud_list(etudset):
|
||||
etuds = [candidats[etudid] for etudid in etudset]
|
||||
etuds.sort(lambda x, y: cmp(x["nom"], y["nom"]))
|
||||
etuds.sort(key=itemgetter("nom"))
|
||||
return etuds
|
||||
|
||||
if submitted:
|
||||
@ -522,8 +523,7 @@ def etuds_select_boxes(
|
||||
infos["comment"] = infos.get("comment", "") # commentaire dans sous-titre boite
|
||||
help = infos.get("help", "")
|
||||
etuds = auth_etuds_by_cat[src_cat]["etuds"]
|
||||
etuds.sort(lambda x, y: cmp(x["nom"], y["nom"]))
|
||||
|
||||
etuds.sort(key=itemgetter("nom"))
|
||||
with_checkbox = (not read_only) and auth_etuds_by_cat[src_cat]["infos"].get(
|
||||
"with_checkbox", True
|
||||
)
|
||||
|
@ -29,6 +29,7 @@
|
||||
"""
|
||||
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
|
||||
from types import StringType
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
import app.scodoc.notesdb as ndb
|
||||
@ -512,7 +513,7 @@ def _make_table_notes(
|
||||
'<td style="padding-left: 50px; vertical-align: top;"><p>',
|
||||
]
|
||||
commentkeys = list(K.items()) # [ (comment, key), ... ]
|
||||
commentkeys.sort(lambda x, y: cmp(int(x[1]), int(y[1])))
|
||||
commentkeys.sort(key=lambda x: int(x[1]))
|
||||
for (comment, key) in commentkeys:
|
||||
C.append(
|
||||
'<span class="colcomment">(%s)</span> <em>%s</em><br/>' % (key, comment)
|
||||
|
@ -29,6 +29,7 @@
|
||||
- statistiques decisions
|
||||
- suivi cohortes
|
||||
"""
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app.scodoc import html_sco_header
|
||||
@ -112,12 +113,7 @@ def _table_etuds_lycees(
|
||||
for l in L:
|
||||
l["nbetuds"] = len(etuds_by_lycee[l["codelycee"]])
|
||||
# L.sort( key=operator.itemgetter('codepostallycee', 'nomlycee') ) argh, only python 2.5+ !!!
|
||||
L.sort(
|
||||
cmp=lambda x, y: cmp(
|
||||
(x["codepostallycee"], x["nomlycee"]),
|
||||
(y["codepostallycee"], y["nomlycee"]),
|
||||
)
|
||||
)
|
||||
L.sort(key=itemgetter("codepostallycee", "nomlycee"))
|
||||
columns_ids = (
|
||||
"nbetuds",
|
||||
"codelycee",
|
||||
|
@ -153,15 +153,16 @@ def do_moduleimpl_withmodule_list(
|
||||
)[0]
|
||||
|
||||
# tri par semestre/UE/numero_matiere/numero_module
|
||||
extr = lambda x: (
|
||||
x["ue"]["numero"],
|
||||
x["ue"]["ue_id"],
|
||||
x["matiere"]["numero"],
|
||||
x["matiere"]["matiere_id"],
|
||||
x["module"]["numero"],
|
||||
x["module"]["code"],
|
||||
modimpls.sort(
|
||||
key=lambda x: (
|
||||
x["ue"]["numero"],
|
||||
x["ue"]["ue_id"],
|
||||
x["matiere"]["numero"],
|
||||
x["matiere"]["matiere_id"],
|
||||
x["module"]["numero"],
|
||||
x["module"]["code"],
|
||||
)
|
||||
)
|
||||
modimpls.sort(lambda x, y: cmp(extr(x), extr(y)))
|
||||
|
||||
return scu.return_text_if_published(modimpls, REQUEST)
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
"""Opérations d'inscriptions aux modules (interface pour gérer options ou parcours)
|
||||
"""
|
||||
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.notesdb as ndb
|
||||
import app.scodoc.sco_utils as scu
|
||||
@ -105,7 +105,7 @@ def moduleimpl_inscriptions_edit(
|
||||
"Etudiant %s inscrit mais inconnu dans la base !!!!!" % ins["etudid"]
|
||||
)
|
||||
ins["etud"] = etuds_info[0]
|
||||
inscrits.sort(lambda x, y: cmp(x["etud"]["nom"], y["etud"]["nom"]))
|
||||
inscrits.sort(key=lambda x: x["etud"]["nom"])
|
||||
in_m = sco_moduleimpl.do_moduleimpl_inscription_list(
|
||||
context, moduleimpl_id=M["moduleimpl_id"]
|
||||
)
|
||||
@ -458,7 +458,7 @@ def _fmt_etud_set(context, ins, max_list_size=7):
|
||||
etuds = []
|
||||
for etudid in ins:
|
||||
etuds.append(sco_etud.get_etud_info(etudid=etudid, filled=True)[0])
|
||||
etuds.sort(lambda x, y: cmp(x["nom"], y["nom"]))
|
||||
etuds.sort(itemgetter("nom"))
|
||||
return ", ".join(
|
||||
[
|
||||
'<a class="discretelink" href="ficheEtud?etudid=%(etudid)s">%(nomprenom)s</a>'
|
||||
|
@ -25,7 +25,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
"""Gestions des "nouvelles"
|
||||
"""Gestion des "nouvelles"
|
||||
"""
|
||||
import datetime
|
||||
import re
|
||||
@ -34,6 +34,7 @@ from cStringIO import StringIO
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.header import Header
|
||||
from operator import itemgetter
|
||||
from stripogram import html2text
|
||||
import PyRSS2Gen # pylint: disable=import-error
|
||||
|
||||
@ -129,7 +130,7 @@ def scolar_news_summary(context, n=5):
|
||||
|
||||
news = list(selected_news.values())
|
||||
# sort by date, descending
|
||||
news.sort(lambda x, y: cmp(y["date"], x["date"]))
|
||||
news.sort(itemgetter("date"), reverse=True)
|
||||
news = news[:n]
|
||||
# mimic EditableTable.list output formatting:
|
||||
for n in news:
|
||||
|
@ -137,16 +137,14 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
||||
# Codes des UE "semestre précédent":
|
||||
ue_prev_codes = list(prev_moy_ue.keys())
|
||||
ue_prev_codes.sort(
|
||||
lambda x, y, prev_ue_acro=prev_ue_acro: cmp( # pylint: disable=undefined-variable
|
||||
prev_ue_acro[x], prev_ue_acro[y]
|
||||
)
|
||||
key=lambda x, prev_ue_acro=prev_ue_acro: prev_ue_acro[ # pylint: disable=undefined-variable
|
||||
x
|
||||
]
|
||||
)
|
||||
# Codes des UE "semestre courant":
|
||||
ue_codes = list(moy_ue.keys())
|
||||
ue_codes.sort(
|
||||
lambda x, y, ue_acro=ue_acro: cmp( # pylint: disable=undefined-variable
|
||||
ue_acro[x], ue_acro[y]
|
||||
)
|
||||
key=lambda x, ue_acro=ue_acro: ue_acro[x] # pylint: disable=undefined-variable
|
||||
)
|
||||
|
||||
sid = sem["semestre_id"]
|
||||
|
@ -47,6 +47,7 @@ Jury de semestre n
|
||||
"""
|
||||
|
||||
import time
|
||||
from operator import itemgetter
|
||||
from reportlab.platypus import Paragraph
|
||||
from reportlab.lib import styles
|
||||
|
||||
@ -97,7 +98,7 @@ def _descr_decisions_ues(context, nt, etudid, decisions_ue, decision_sem):
|
||||
uelist.append(nt.get_etud_ue_status(etudid, ue["ue_id"])["ue"])
|
||||
except KeyError:
|
||||
pass
|
||||
uelist.sort(lambda x, y: cmp(x["numero"], y["numero"]))
|
||||
uelist.sort(itemgetter("numero"))
|
||||
|
||||
return uelist
|
||||
|
||||
|
@ -35,6 +35,7 @@ import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
|
||||
import re
|
||||
import time
|
||||
import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app.scodoc import notesdb as ndb
|
||||
@ -453,7 +454,7 @@ def table_suivi_cohorte(
|
||||
for s in sems:
|
||||
d, m, y = [int(x) for x in s["date_debut"].split("/")]
|
||||
s["date_debut_dt"] = datetime.datetime(y, m, d)
|
||||
sems.sort(lambda x, y: cmp(x["date_debut_dt"], y["date_debut_dt"]))
|
||||
sems.sort(key=itemgetter("date_debut_dt"))
|
||||
|
||||
# 2-- Pour chaque semestre, trouve l'ensemble des etudiants venant de sem
|
||||
logt("B: etuds sets")
|
||||
@ -910,7 +911,7 @@ def _descr_etud_set(context, etudids):
|
||||
for etudid in etudids:
|
||||
etuds.append(sco_etud.get_etud_info(etudid=etudid, filled=True)[0])
|
||||
# sort by name
|
||||
etuds.sort(lambda x, y: cmp(x["nom"], y["nom"]))
|
||||
etuds.sort(itemgetter("nom"))
|
||||
return ", ".join([e["nomprenom"] for e in etuds])
|
||||
|
||||
|
||||
@ -1077,7 +1078,7 @@ def tsp_grouped_list(context, codes_etuds):
|
||||
)
|
||||
L.append(l)
|
||||
# tri par effectifs décroissants
|
||||
L.sort(lambda x, y: cmp(y["nb"], x["nb"]))
|
||||
L.sort(key=itemgetter("nb"))
|
||||
return L
|
||||
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
import time
|
||||
import pprint
|
||||
from operator import itemgetter
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
import app.scodoc.notesdb as ndb
|
||||
@ -423,7 +424,7 @@ def list_synch(context, sem, anneeapogee=None):
|
||||
return etud
|
||||
|
||||
etuds = [key2etud(x, etud_apo) for x in etudset]
|
||||
etuds.sort(lambda x, y: cmp(x["nom"], y["nom"]))
|
||||
etuds.sort(itemgetter("nom"))
|
||||
return etuds
|
||||
|
||||
#
|
||||
|
@ -35,6 +35,7 @@ import time
|
||||
import datetime
|
||||
import jaxml
|
||||
import pprint
|
||||
from operator import itemgetter
|
||||
|
||||
from flask import url_for, g
|
||||
from flask import current_app
|
||||
@ -1207,7 +1208,7 @@ def formsemestre_enseignants_list(context, REQUEST, formsemestre_id, format="htm
|
||||
sem_ens[ens]["_email_target"] = "mailto:%s" % sem_ens[ens]["email"]
|
||||
|
||||
sem_ens_list = list(sem_ens.values())
|
||||
sem_ens_list.sort(lambda x, y: cmp(x["nomprenom"], y["nomprenom"]))
|
||||
sem_ens_list.sort(itemgetter("nomprenom"))
|
||||
|
||||
# --- Generate page with table
|
||||
title = "Enseignants de " + sem["titremois"]
|
||||
|
Loading…
Reference in New Issue
Block a user