From 1675a3a90118579b0ecbb122ccc3027e311399e1 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Thu, 20 Jul 2017 18:20:21 +0800 Subject: query date from oldest to newest Change-Id: I3d0345bb85967f48617c485bbee1dfe6fa04a644 Signed-off-by: SerenaFeng --- .../opnfv_testapi/resources/result_handlers.py | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'utils/test/testapi/opnfv_testapi') diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py index 1ccafd507..2bf1792f2 100644 --- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py @@ -66,7 +66,7 @@ class GenericResultHandler(handlers.GenericApiHandler): del query['public'] if role != "reviewer": query['user'] = openid - elif k != 'last' and k != 'page': + elif k not in ['last', 'page', 'descend']: query[k] = v if date_range: query['start_date'] = date_range @@ -167,18 +167,27 @@ class ResultsCLHandler(GenericResultHandler): @type signed: L{string} @in signed: query @required signed: False + @param descend: true, newest2oldest; false, oldest2newest + @type descend: L{string} + @in descend: query + @required descend: False """ - limitations = {'sort': {'_id': -1}} - last = self.get_query_argument('last', 0) - if last is not None: - last = self.get_int('last', last) - limitations.update({'last': last}) + def descend_limit(): + descend = self.get_query_argument('descend', 'true') + return -1 if descend.lower() == 'true' else 1 - page = self.get_query_argument('page', None) - if page is not None: - page = self.get_int('page', page) - limitations.update({'page': page, - 'per_page': CONF.api_results_per_page}) + def last_limit(): + return self.get_int('last', self.get_query_argument('last', 0)) + + def page_limit(): + return self.get_int('page', self.get_query_argument('page', 0)) + + limitations = { + 'sort': {'_id': descend_limit()}, + 'last': last_limit(), + 'page': page_limit(), + 'per_page': CONF.api_results_per_page + } self._list(query=self.set_query(), **limitations) -- cgit 1.2.3-korg