diff --git a/tabellio/searchform/form.py b/tabellio/searchform/form.py index 194b290..f714b1d 100644 --- a/tabellio/searchform/form.py +++ b/tabellio/searchform/form.py @@ -817,6 +817,16 @@ class SearchView(BrowserView): return 99999 return 0 + ordered_sessions = tabellio.config.utils.get_ordered_sessions() + def cmp_session_name(x, y): + if x is y or x == y: + return 0 + if x not in ordered_sessions: + return -1 + if y not in ordered_sessions: + return +1 + return cmp(ordered_sessions.index(x), ordered_sessions.index(y)) + def cmp_dostype(x, y): if not (x.dostype is None or y.dostype is None or x.dostype is Missing.Value or y.dostype is Missing.Value): @@ -826,7 +836,7 @@ class SearchView(BrowserView): t = -cmp(x.dostype, y.dostype) t = cmp(type_x, type_y) if t == 0: - t = -cmp(x.session, y.session) + t = -cmp_session_name(x.session, y.session) if t == 0: t = -cmp(x.no, y.no) return t @@ -840,7 +850,7 @@ class SearchView(BrowserView): t = -cmp(x.questype, y.questype) t = cmp(type_x, type_y) if t == 0: - t = -cmp(x.session, y.session) + t = -cmp_session_name(x.session, y.session) if t == 0: t = -cmp(x.dateDoc, y.dateDoc) return t @@ -848,15 +858,17 @@ class SearchView(BrowserView): def cmp_number(x, y): t = -cmp(get_no_as_int(x.no), get_no_as_int(y.no)) if t == 0: - t = -cmp(x.session, y.session) + t = -cmp_session_name(x.session, y.session) if t == 0: t = cmp(x.nodoc, y.nodoc) return t def cmp_session(x, y): - t = -cmp(x.session, y.session) + t = -cmp_session_name(x.session, y.session) if t == 0: t = -cmp(get_no_as_int(x.no), get_no_as_int(y.no)) + if t == 0 and hasattr(x, 'nodoc'): + t = cmp(x.nodoc, y.nodoc) return t cmp_function = None @@ -875,6 +887,7 @@ class SearchView(BrowserView): cmp_function = cmp_session catalog = getToolByName(self.context, 'portal_catalog') + print 'kw:', kw return sorted(catalog(**kw), cmp_function) def deputy_search_form(self):