From d3c16d62b4629927143940cdf221803510614778 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 27 Jun 2010 14:41:38 +0200 Subject: [PATCH] brin sort in line with query structure --- pandora/backend/views.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pandora/backend/views.py b/pandora/backend/views.py index 251078b5e..5f9e8914b 100644 --- a/pandora/backend/views.py +++ b/pandora/backend/views.py @@ -78,15 +78,9 @@ def api_error(request): def _order_query(qs, sort, prefix='sort__'): order_by = [] - if isinstance(sort, basestring): - sort = [sort, ] for e in sort: - desc = '' - if e.startswith('-'): - e = e[1:] - desc = '-' - order = {'id': 'movieId'}.get(e, e) - order = '%s%s%s' % (desc, prefix, order) + key = {'id': 'movieId'}.get(e['key'], e['key']) + order = '%s%s%s' % (e['operator'], prefix, key) order_by.append(order) if order_by: qs = qs.order_by(*order_by) @@ -122,12 +116,21 @@ def _parse_query(data, user): def api_find(request): ''' param data - {'query': query, 'sort': string, 'range': array} + {'query': query, 'sort': array, 'range': array} query: query object, more on query syntax at https://wiki.0x2620.org/wiki/0xdb2QuerySyntax - sort: string or arrays of keys; to sort key in descending order prefix with - - default: ['director', '-year'] + sort: array of key, operator dics + [ + { + key: "year", + operator: "-" + }, + { + key: "director", + operator: "" + } + ] range: result range, array [from, to] keys: array of keys to return group: group elements by, country, genre, director...