[gen] added the possibility to define a sortOrder of a Search class.

This commit is contained in:
Gaetan Delannay 2012-05-25 14:27:53 +02:00
parent 9368138efd
commit aaaccb0669
2 changed files with 11 additions and 5 deletions

View file

@ -298,10 +298,12 @@ class Import:
class Search: class Search:
'''Used for specifying a search for a given type.''' '''Used for specifying a search for a given type.'''
def __init__(self, name, group=None, sortBy='', limit=None, **fields): def __init__(self, name, group=None, sortBy='', sortOrder='asc', limit=None,
**fields):
self.name = name self.name = name
self.group = group # Searches may be visually grouped in the portlet self.group = group # Searches may be visually grouped in the portlet
self.sortBy = sortBy self.sortBy = sortBy
self.sortOrder = sortOrder
self.limit = limit self.limit = limit
# In the dict below, keys are indexed field names and values are # In the dict below, keys are indexed field names and values are
# search values. # search values.

View file

@ -288,9 +288,10 @@ class ToolMixin(BaseMixin):
currently logged user can't see. currently logged user can't see.
The result is sorted according to the potential sort key defined in The result is sorted according to the potential sort key defined in
the Search instance (Search.sortBy). But if parameter p_sortBy is the Search instance (Search.sortBy, together with Search.sortOrder).
given, it defines or overrides the sort. In this case, p_sortOrder But if parameter p_sortBy is given, it defines or overrides the sort.
gives the order (*asc*ending or *desc*ending). In this case, p_sortOrder gives the order (*asc*ending or
*desc*ending).
If p_filterKey is given, it represents an additional search parameter If p_filterKey is given, it represents an additional search parameter
to take into account: the corresponding search value is in to take into account: the corresponding search value is in
@ -329,6 +330,8 @@ class ToolMixin(BaseMixin):
sortKey = search.sortBy sortKey = search.sortBy
if sortKey: if sortKey:
params['sort_on'] = Search.getIndexName(sortKey, usage='sort') params['sort_on'] = Search.getIndexName(sortKey, usage='sort')
if search.sortOrder == 'desc': params['sort_order'] = 'reverse'
else: params['sort_order'] = None
# Determine or override sort if specified. # Determine or override sort if specified.
if sortBy: if sortBy:
params['sort_on'] = Search.getIndexName(sortBy, usage='sort') params['sort_on'] = Search.getIndexName(sortBy, usage='sort')
@ -917,6 +920,7 @@ class ToolMixin(BaseMixin):
password = request.get('__ac_password', '') password = request.get('__ac_password', '')
elif cookie and (cookie != 'deleted'): elif cookie and (cookie != 'deleted'):
cookieValue = base64.decodestring(urllib.unquote(cookie)) cookieValue = base64.decodestring(urllib.unquote(cookie))
if ':' in cookieValue:
login, password = cookieValue.split(':') login, password = cookieValue.split(':')
# Try to authenticate this user # Try to authenticate this user
user = self.authenticate(login, password, request) user = self.authenticate(login, password, request)