sort by type of multiple object types
This commit is contained in:
parent
e163e4f413
commit
3b30ee78e4
|
@ -29,6 +29,25 @@ class Cmp:
|
|||
t = cmp(x.nodoc, y.nodoc)
|
||||
return t
|
||||
|
||||
def cmp_multitype(self, x, y):
|
||||
type_x = 'ZZZZ'
|
||||
type_y = 'ZZZZ'
|
||||
for attr in ('doctype', 'dostype', 'questype'):
|
||||
if hasattr(x, attr) and getattr(x, attr) not in (None, Missing.Value):
|
||||
dtype = getattr(x, attr)
|
||||
type_x = normalizer.normalize(MAPPING.get(dtype, dtype))
|
||||
if hasattr(y, attr) and getattr(y, attr) not in (None, Missing.Value):
|
||||
dtype = getattr(y, attr)
|
||||
type_y = normalizer.normalize(MAPPING.get(dtype, dtype))
|
||||
t = cmp(type_x, type_y)
|
||||
if t == 0:
|
||||
t = -cmp(x.session, y.session)
|
||||
if t == 0:
|
||||
t = -cmp(x.no, y.no)
|
||||
if t == 0:
|
||||
t = cmp(x.nodoc, y.nodoc)
|
||||
return t
|
||||
|
||||
_ordered_sessions = None
|
||||
def ordered_sessions(self):
|
||||
if self._ordered_sessions: return self._ordered_sessions
|
||||
|
|
|
@ -128,7 +128,7 @@ class SimpleSearchView(BrowserView):
|
|||
if sorton == 'session':
|
||||
cmpf = cmpfunctions.Cmp().cmp_session
|
||||
elif sorton == 'type':
|
||||
cmpf = cmpfunctions.Cmp().cmp_doctype
|
||||
cmpf = cmpfunctions.Cmp().cmp_multitype
|
||||
elif sorton == 'number':
|
||||
cmpf = cmpfunctions.Cmp().cmp_number
|
||||
return sorted(c, cmpf);
|
||||
|
|
Reference in New Issue