aboutsummaryrefslogtreecommitdiff
path: root/app/handlers/base.py
diff options
context:
space:
mode:
authorMilo Casagrande <milo.casagrande@linaro.org>2014-09-08 14:04:46 +0200
committerMilo Casagrande <milo.casagrande@linaro.org>2014-09-08 14:04:46 +0200
commit3fc27de0bc453b7b12d79c5a5093d4026256c3fe (patch)
treee75e90f3adab02ac8253e268382bb04f3ce06041 /app/handlers/base.py
parent2a25e648f0078bc1aca331dc548a7c8a7c52b0d6 (diff)
boot: Implement DELETE method.
* Add a more complex DELETE method that accepts either an ID or a query to specify which boot reports to delete. This is specific only to the boot handler. * Refactor the base handler and created a new method to retrieve the date_range query. This is necesary to limit the boot delete method to not include date range deletion. * Add boot handler test focused on the DELETE implementation. Change-Id: I6ac159e8bddd5f0a094692ed891aefa1b0f31a41
Diffstat (limited to 'app/handlers/base.py')
-rw-r--r--app/handlers/base.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/handlers/base.py b/app/handlers/base.py
index 3c94255..2e2262f 100644
--- a/app/handlers/base.py
+++ b/app/handlers/base.py
@@ -415,12 +415,13 @@ class BaseHandler(RequestHandler):
if self.request.arguments:
spec = self._get_query_spec()
+ spec = self._get_and_add_date_range(spec)
sort = self._get_query_sort()
fields = self._get_query_fields()
return (spec, sort, fields)
- def _get_query_spec(self):
+ def _get_query_spec(self, method='GET'):
"""Get values from the query string to build a `spec` data structure.
A `spec` data structure is a dictionary whose keys are the keys
@@ -431,12 +432,20 @@ class BaseHandler(RequestHandler):
spec = {
k: v for k, v in [
(key, val)
- for key in self._valid_keys('GET')
+ for key in self._valid_keys(method)
for val in self.get_query_arguments(key)
if val is not None
]
}
+ return spec
+
+ def _get_and_add_date_range(self, spec):
+ """Retrieve the `date_range` query from the request.
+
+ :param spec: The dictionary where to store the key-value.
+ :return The passed spec.
+ """
date_range = self.get_query_argument(DATE_RANGE_KEY, default=None)
if date_range:
# Today needs to be set at the end of the day!
@@ -446,7 +455,6 @@ class BaseHandler(RequestHandler):
previous = self._calculate_date_range(date_range)
spec[CREATED_KEY] = {'$gte': previous, '$lt': today}
-
return spec
def _get_query_sort(self):