diff options
author | Serena Feng <feng.xiaowei@zte.com.cn> | 2017-08-22 01:42:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-22 01:42:55 +0000 |
commit | 52ad2a4cb4099431ca6783d78b81993f6ed4e6a3 (patch) | |
tree | 3dd2373e48a4bead9269caeeb46c03984ad21774 /testapi/opnfv_testapi | |
parent | 2125937047aac348645e5083654434af8d134ca4 (diff) | |
parent | 30868451cb3a59bf364a82854079e97e272d1438 (diff) |
Merge "bugfix: OperationFailure: the limit must be positive"
Diffstat (limited to 'testapi/opnfv_testapi')
-rw-r--r-- | testapi/opnfv_testapi/resources/handlers.py | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/testapi/opnfv_testapi/resources/handlers.py b/testapi/opnfv_testapi/resources/handlers.py index 7090e99..ed55c70 100644 --- a/testapi/opnfv_testapi/resources/handlers.py +++ b/testapi/opnfv_testapi/resources/handlers.py @@ -110,22 +110,23 @@ class GenericApiHandler(web.RequestHandler): pipelines.append({'$match': query}) total_pages = 0 - if page > 0: - cursor = dbapi.db_list(self.table, query) - records_count = yield cursor.count() - total_pages, return_nr = self._calc_total_pages(records_count, - last, - page, - per_page) - pipelines = self._set_pipelines(pipelines, - sort, - return_nr, - page, - per_page) - cursor = dbapi.db_aggregate(self.table, pipelines) data = list() - while (yield cursor.fetch_next): - data.append(self.format_data(cursor.next_object())) + cursor = dbapi.db_list(self.table, query) + records_count = yield cursor.count() + if records_count > 0: + if page > 0: + total_pages, return_nr = self._calc_total_pages(records_count, + last, + page, + per_page) + pipelines = self._set_pipelines(pipelines, + sort, + return_nr, + page, + per_page) + cursor = dbapi.db_aggregate(self.table, pipelines) + while (yield cursor.fetch_next): + data.append(self.format_data(cursor.next_object())) if res_op is None: res = {self.table: data} else: |