Commit 01671fa5 authored by Yusei Tahara's avatar Yusei Tahara Committed by Arnaud Fontaine

Support new sorting feature which user can specify order of sort explicitly.

parent 143c9a15
...@@ -513,6 +513,19 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -513,6 +513,19 @@ class SelectionTool( BaseTool, SimpleItem ):
if sort_on is None: if sort_on is None:
listbox_id, sort_on = form["setSelectionQuickSortOrder"].split(".", 1) listbox_id, sort_on = form["setSelectionQuickSortOrder"].split(".", 1)
# Sort order can be specified in sort_on.
forced_sort_order = None
if sort_on is not None:
if sort_on.endswith(':asc'):
forced_sort_order = 'ascending'
sort_on = sort_on[:-4]
elif sort_on.endswith(':desc'):
forced_sort_order = 'descending'
sort_on = sort_on[:-5]
elif sort_on.endswith(':none'):
forced_sort_order = 'none'
sort_on = sort_on[:-5]
if REQUEST is not None: if REQUEST is not None:
if listbox_id is not None: if listbox_id is not None:
selection_name_key = "%s_list_selection_name" %listbox_id selection_name_key = "%s_list_selection_name" %listbox_id
...@@ -522,6 +535,17 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -522,6 +535,17 @@ class SelectionTool( BaseTool, SimpleItem ):
selection = self.getSelectionFor(selection_name, REQUEST=REQUEST) selection = self.getSelectionFor(selection_name, REQUEST=REQUEST)
if selection is not None: if selection is not None:
if forced_sort_order is not None:
if forced_sort_order == 'none':
temporary_new_sort_on = []
else:
temporary_new_sort_on = [(sort_on, forced_sort_order)]
# Allow user to sort by multiple columns
new_sort_on = [s
for s in self.getSelectionSortOrder(selection_name)
if s[0]!=sort_on]
new_sort_on.extend(temporary_new_sort_on)
else:
current_sort_on = self.getSelectionSortOrder(selection_name) current_sort_on = self.getSelectionSortOrder(selection_name)
# We must first switch from asc to desc and vice-versa if sort_order exists # We must first switch from asc to desc and vice-versa if sort_order exists
# in selection # in selection
...@@ -535,9 +559,9 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -535,9 +559,9 @@ class SelectionTool( BaseTool, SimpleItem ):
else: else:
new_sort_on = [(sort_on,'ascending')] new_sort_on = [(sort_on,'ascending')]
break break
# And if no one exists, we just set ascending sort # And if no one exists, we just set sort
if n == 0: if n == 0:
new_sort_on = [(sort_on,'ascending')] new_sort_on = [(sort_on, 'ascending')]
selection.edit(sort_on=new_sort_on) selection.edit(sort_on=new_sort_on)
if REQUEST is not None: if REQUEST is not None:
......
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