Commit 658db564 authored by Sebastien Robin's avatar Sebastien Robin

make the sort feature working for many columns


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2394 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d5d5c5f1
...@@ -1170,6 +1170,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1170,6 +1170,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
try: REQUEST=self.REQUEST try: REQUEST=self.REQUEST
except AttributeError: pass except AttributeError: pass
LOG('SQLCatalog.buildSQLQuery, kw',0,kw)
# If kw is not set, then use REQUEST instead # If kw is not set, then use REQUEST instead
if kw is None or kw == {}: if kw is None or kw == {}:
kw = REQUEST kw = REQUEST
...@@ -1247,16 +1248,28 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1247,16 +1248,28 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
so=kw['sort_order'] so=kw['sort_order']
else: so=None else: so=None
# We must now turn so into a string if so is not None:
if type(so) is not type('a'): if type(so) is type('a'):
so = 'ascending' if so.find(',')>0:
so = [x.strip() for x in so.split(',')]
else:
so = [so]
# We must now turn sort_index into new_index = []
# a dict with keys as sort keys and values as sort order if sort_index is not None:
if type(sort_index) is type('a'): if type(sort_index) is type('a'):
sort_index = [(sort_index, so)] if sort_index.find(',')>0:
elif type(sort_index) is not type(()) and type(sort_index) is not type([]): index_list = [x.strip() for x in sort_index.split(',')]
sort_index = None else:
index_list = [sort_index]
for index in index_list:
if index.find(' ') > 0:
new_index.append([x.strip() for x in sort_index.split(' ')])
elif so is not None and len(so)==len(index_list):
new_index.append([index,so[index_list.index(index)]])
else:
new_index.append([index,'ascending'])
sort_index = new_index
# If sort_index is a dictionnary # If sort_index is a dictionnary
# then parse it and change it # then parse it and change it
...@@ -1269,7 +1282,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1269,7 +1282,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
k = acceptable_key_map[k][0] + '.' + k k = acceptable_key_map[k][0] + '.' + k
elif query_table: elif query_table:
k = query_table + '.' + k k = query_table + '.' + k
if v == 'descending' or v == 'reverse': if v == 'descending' or v == 'reverse' or v == 'DESC':
from_table_dict[acceptable_key_map[k][0]] = acceptable_key_map[k][0] # We need this table to sort on it from_table_dict[acceptable_key_map[k][0]] = acceptable_key_map[k][0] # We need this table to sort on it
new_sort_index += ['%s DESC' % k] new_sort_index += ['%s DESC' % k]
else: else:
...@@ -1278,6 +1291,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1278,6 +1291,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
sort_index = join(new_sort_index,',') sort_index = join(new_sort_index,',')
sort_on = str(sort_index) sort_on = str(sort_index)
except: except:
LOG('SQLCatalog.buildSQLQuery',0,'WARNING, Unable to build the new sort index')
pass pass
# Rebuild keywords to behave as new style query (_usage='toto:titi' becomes {'toto':'titi'}) # Rebuild keywords to behave as new style query (_usage='toto:titi' becomes {'toto':'titi'})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment