use chronological order in session sort (#984)

This commit is contained in:
Frédéric Péters 2011-11-24 10:26:53 +01:00
parent b87b9bbe93
commit cbe5503b0f
1 changed files with 17 additions and 4 deletions

View File

@ -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):