aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2015-11-24 08:23:34 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2015-11-24 08:23:34 +0100
commitcb7e07feef16db6dffefb18101ca21d81d3b8e42 (patch)
treeb5c75f7391ebdfa9742bae37a46210ad1703f920 /pyaggr3g470r/views
parentAdd a way to get the json encoded by jquery in the URL when using the GET met... (diff)
downloadnewspipe-cb7e07feef16db6dffefb18101ca21d81d3b8e42.tar.gz
newspipe-cb7e07feef16db6dffefb18101ca21d81d3b8e42.tar.bz2
newspipe-cb7e07feef16db6dffefb18101ca21d81d3b8e42.zip
Improved the way arguments are parsed (usefull for the mobile version of pyAggr3g470r).
Diffstat (limited to 'pyaggr3g470r/views')
-rw-r--r--pyaggr3g470r/views/api/common.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py
index ea5172c2..6da93a3b 100644
--- a/pyaggr3g470r/views/api/common.py
+++ b/pyaggr3g470r/views/api/common.py
@@ -21,6 +21,7 @@ routes :
DELETE resources
-> to delete several
"""
+import ast
import json
import logging
import dateutil.parser
@@ -161,19 +162,21 @@ class PyAggResourceMulti(PyAggAbstractResource):
"""retrieve several objects. filters can be set in the payload on the
different fields of the object, and a limit can be set in there as well
"""
- args = None
- args = [item[0] for item in request.args.items()]
- args = json.loads(args[0])
-
try:
limit = request.json.pop('limit', 10)
order_by = request.json.pop('order_by', None)
query = self.controller.read(**request.json)
except:
- if None is not args:
- limit, order_by, query = 10, None, self.controller.read(**args)
- else:
- limit, order_by, query = 10, None, self.controller.read()
+ args = {}
+ for k, v in request.args.items():
+ if k in self.attrs.keys():
+ if self.attrs[k]['type'] in [bool, int]:
+ args[k] = ast.literal_eval(v)
+ else:
+ args[k] = v
+ limit = request.args.get('limit', 10)
+ order_by = request.args.get('order_by', None)
+ query = self.controller.read(**args)
if order_by:
query = query.order_by(order_by)
if limit:
bgstack15