Commit 01a11cd7 authored by Sebastien Robin's avatar Sebastien Robin

allow to add one more parameter to sort-on so it is possible to sort a string...

allow to add one more parameter to sort-on so it is possible to sort a string column like an int column


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3904 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4413e4c5
...@@ -1276,14 +1276,22 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1276,14 +1276,22 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
elif type(sort_index) is not type(()) and type(sort_index) is not type([]): elif type(sort_index) is not type(()) and type(sort_index) is not type([]):
sort_index = None sort_index = None
# If sort_index is a dictionnary # If sort_index is a dictionnary
# then parse it and change it # then parse it and change it
sort_on = None sort_on = None
#LOG('sorting', 0, str(sort_index)) #LOG('sorting', 0, str(sort_index))
if sort_index is not None: if sort_index is not None:
new_sort_index = []
for sort in sort_index:
if len(sort)==2:
new_sort_index.append((sort[0],sort[1],None))
elif len(sort)==3:
new_sort_index.append(sort)
sort_index = new_sort_index
try: try:
new_sort_index = [] new_sort_index = []
for (key , v) in sort_index: for (key , so, as_type) in sort_index:
key_is_acceptable = key in acceptable_keys # Only calculate once key_is_acceptable = key in acceptable_keys # Only calculate once
key_is_related = key in related_keys key_is_related = key in related_keys
if key_is_acceptable or key_is_related: if key_is_acceptable or key_is_related:
...@@ -1308,7 +1316,9 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1308,7 +1316,9 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
key = 'catalog.uid' key = 'catalog.uid'
# Add table to table dict # Add table to table dict
from_table_dict[acceptable_key_map[key][0]] = acceptable_key_map[key][0] # We use catalog by default from_table_dict[acceptable_key_map[key][0]] = acceptable_key_map[key][0] # We use catalog by default
if v == 'descending' or v == 'reverse' or v == 'DESC': if as_type == 'int':
key = 'CAST(' + key + ' AS SIGNED)'
if so == 'descending' or so == 'reverse' or so == 'DESC':
new_sort_index += ['%s DESC' % key] new_sort_index += ['%s DESC' % key]
else: else:
new_sort_index += ['%s' % key] new_sort_index += ['%s' % key]
......
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