summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@0d.be>2011-12-04 12:02:53 (GMT)
committerFrédéric Péters <fpeters@0d.be>2011-12-04 12:04:01 (GMT)
commit3b30ee78e4b3ff06986097234fe6c9509181f709 (patch)
treedcb52bb3e3a7cac23f268fb147acf7bc232c5277
parente163e4f4138fc6569d6d1c802ad6283b3e7de025 (diff)
downloadtabellio.searchform-3b30ee78e4b3ff06986097234fe6c9509181f709.zip
tabellio.searchform-3b30ee78e4b3ff06986097234fe6c9509181f709.tar.gz
tabellio.searchform-3b30ee78e4b3ff06986097234fe6c9509181f709.tar.bz2
sort by type of multiple object types
-rw-r--r--tabellio/searchform/cmpfunctions.py19
-rw-r--r--tabellio/searchform/simple.py2
2 files changed, 20 insertions, 1 deletions
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);