aboutsummaryrefslogtreecommitdiff
path: root/app/handlers/base.py
diff options
context:
space:
mode:
authorMilo Casagrande <milo.casagrande@linaro.org>2014-04-18 13:28:14 +0200
committerMilo Casagrande <milo.casagrande@linaro.org>2014-04-18 13:28:14 +0200
commitc9d12126b051b93a90e0fe9493ac81c58dcdf5c7 (patch)
tree66c6c68f7535e26de8680183efed64f548844146 /app/handlers/base.py
parenta992222a2fc6494d8e5d40242fbf378059aa185a (diff)
Remove MAX_LIMIT and add _get method.
* Remove the max limit on the number of documents to retrieve, client should specify it. * Add a _get method that subclasses should override if they need to provide a custom GET method.
Diffstat (limited to 'app/handlers/base.py')
-rw-r--r--app/handlers/base.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/app/handlers/base.py b/app/handlers/base.py
index 7165512..3d37eb8 100644
--- a/app/handlers/base.py
+++ b/app/handlers/base.py
@@ -35,9 +35,8 @@ from utils.db import (
from utils.log import get_log
from utils.validator import is_valid_json
-# Default and maximum limit for how many results to get back from the db.
-DEFAULT_LIMIT = 20
-MAX_LIMIT = 100
+# Default limit for how many results to get back: 0 means all.
+DEFAULT_LIMIT = 0
class BaseHandler(RequestHandler):
@@ -268,17 +267,31 @@ class BaseHandler(RequestHandler):
limit = int(
self.get_query_argument('limit', default=DEFAULT_LIMIT)
)
- if limit > MAX_LIMIT:
- limit = MAX_LIMIT
self.executor.submit(
- partial(find_and_count, self.collection, limit, skip)
+ partial(self._get, limit, skip)
).add_done_callback(
lambda future:
tornado.ioloop.IOLoop.instance().add_callback(
partial(self._get_callback, future.result()))
)
+ def _get(self, limit, skip):
+ """Method called by the real GET one.
+
+ For special uses, sublcasses should override this one and provide their
+ own implementation.
+
+ By default it executes a search on all the documents in a collection,
+ returnig at max `limit` documents.
+
+ It shoul 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
+ """
+ return find_and_count(self.collection, limit, skip)
+
def write_error(self, status_code, **kwargs):
if kwargs.get('message', None):
status_message = kwargs['message']