diff options
author | Milo Casagrande <milo.casagrande@linaro.org> | 2014-04-25 11:29:58 +0200 |
---|---|---|
committer | Milo Casagrande <milo.casagrande@linaro.org> | 2014-04-25 11:29:58 +0200 |
commit | ac791cc31c2ead4f27063a960ae294304e16362d (patch) | |
tree | 05f8b12d457d8c404f811c8a25799f8ec78e5cfc /app/handlers/base.py | |
parent | 3f3a9b298ba258b455f5810cdd697c6b57e113f2 (diff) |
Handle aggregate, add more valid GET keys.
* Handle the aggregate query on the BaseHandler.
* Add more valid GET keys for job and defconfig.
* Fix a test.
Diffstat (limited to 'app/handlers/base.py')
-rw-r--r-- | app/handlers/base.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/app/handlers/base.py b/app/handlers/base.py index 84544d6..2e59da1 100644 --- a/app/handlers/base.py +++ b/app/handlers/base.py @@ -22,7 +22,10 @@ import types from bson.json_util import dumps from functools import partial -from pymongo import DESCENDING +from pymongo import ( + ASCENDING, + DESCENDING, +) from tornado.web import ( RequestHandler, asynchronous, @@ -30,6 +33,7 @@ from tornado.web import ( from models import DB_NAME from utils.db import ( + aggregate, find_and_count, find_one, ) @@ -287,7 +291,7 @@ class BaseHandler(RequestHandler): By default it executes a search on all the documents in a collection, returnig all the documents found. - It shoul return a dictionary with at least the following fields: + It should return a dictionary with at least the following fields: `result` - that will hold the actual operation result `count` - the total number of results available `limit` - how many results have been collected @@ -297,9 +301,19 @@ class BaseHandler(RequestHandler): spec, sort, fields = self._get_query_args() - return find_and_count( - self.collection, limit, skip, spec=spec, fields=fields, sort=sort - ) + unique = self.get_query_argument('aggregate', default=None) + if unique: + self.log.info("Performing aggregation on %s", unique) + return aggregate(self.collection, unique, sort=sort, fields=fields) + else: + return find_and_count( + self.collection, + limit, + skip, + spec=spec, + fields=fields, + sort=sort + ) def _get_query_args(self): """Retrieve all the arguments from the query string. @@ -350,7 +364,7 @@ class BaseHandler(RequestHandler): ) # Wrong number for sort order? Force descending. - if sort_order != 1 and sort_order != -1: + if sort_order != ASCENDING and sort_order != DESCENDING: self.log.warn("Wrong sort order used: %d", sort_order) sort_order = DESCENDING |