diff --git a/tabellio/searchform/cmpfunctions.py b/tabellio/searchform/cmpfunctions.py index dcf6cab..b8b0e47 100644 --- a/tabellio/searchform/cmpfunctions.py +++ b/tabellio/searchform/cmpfunctions.py @@ -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 diff --git a/tabellio/searchform/simple.py b/tabellio/searchform/simple.py index 966b537..44cc561 100644 --- a/tabellio/searchform/simple.py +++ b/tabellio/searchform/simple.py @@ -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);