diff --git a/product/ERP5Form/Selection.py b/product/ERP5Form/Selection.py index e614b711cac5818df67b5bd35d2622c6f1ab7d7c..8b46f4c78583198269e7979166c748a5a39bcbb9 100755 --- a/product/ERP5Form/Selection.py +++ b/product/ERP5Form/Selection.py @@ -183,14 +183,7 @@ class Selection(Acquisition.Implicit, Traversable, Persistent): if len(sort_on) == 0: sort_on = getattr(self, 'default_sort_on', []) if len(sort_on) > 0: - new_sort_index = [] - for (k , v) in sort_on: - if v == 'descending' or v == 'reverse': - new_sort_index += ['%s DESC' % k] - else: - new_sort_index += ['%s' % k] - sort_order_string = string.join(new_sort_index,',') - self.params['sort_on'] = sort_order_string + self.params['sort_on'] = sort_on elif self.params.has_key('sort_on'): del self.params['sort_on'] if method is not None: @@ -257,6 +250,13 @@ class Selection(Acquisition.Implicit, Traversable, Persistent): self.params = {} return self.params + security.declarePublic('getSortOrder') + def getSortOrder(self): + """ + Return sort order stored in selection + """ + return self.sort_on + security.declarePublic('getListUrl') def getListUrl(self): result = '' diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index c73f67080ca9c2e3543612a531c5b96b35047469..9a933c93ea1fb0df7e3cb3414f2016380bff7065 100755 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -1255,30 +1255,40 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): else: so = [so] - new_index = [] - if sort_index is not None: - if type(sort_index) is type('a'): - if sort_index.find(',')>0: - index_list = [x.strip() for x in sort_index.split(',')] - else: - index_list = [sort_index] - for index in index_list: - if index.find(' ') > 0: - new_index.append([x.strip() for x in 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 + # We must now turn sort_index into + # a dict with keys as sort keys and values as sort order + if type(sort_index) is type('a'): + sort_index = [(sort_index, so)] + elif type(sort_index) is not type(()) and type(sort_index) is not type([]): + sort_index = None + + #new_index = [] + #if sort_index is not None: + # if type(sort_index) is type('a'): + # if sort_index.find(',')>0: + # index_list = [x.strip() for x in sort_index.split(',')] + # else: + # index_list = [sort_index] + # for index in index_list: + # if index.find(' ') > 0: + # new_index.append([x.strip() for x in 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 # then parse it and change it sort_on = None + #LOG('sorting', 0, str(sort_index)) if sort_index is not None: try: new_sort_index = [] for (k , v) in sort_index: - if len(acceptable_key_map[k]) == 1 : + if '.' in k: + pass + elif len(acceptable_key_map[k]) == 1 : k = acceptable_key_map[k][0] + '.' + k elif query_table: k = query_table + '.' + k