[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:
'''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.group = group # Searches may be visually grouped in the portlet
self.sortBy = sortBy
self.sortOrder = sortOrder
self.limit = limit
# In the dict below, keys are indexed field names and values are
# search values.

View file

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