aboutsummaryrefslogtreecommitdiff
path: root/src/web/views/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/views/api')
-rw-r--r--src/web/views/api/__init__.py3
-rw-r--r--src/web/views/api/v2/__init__.py3
-rw-r--r--src/web/views/api/v2/article.py (renamed from src/web/views/api/article.py)2
-rw-r--r--src/web/views/api/v2/category.py (renamed from src/web/views/api/category.py)2
-rw-r--r--src/web/views/api/v2/common.py (renamed from src/web/views/api/common.py)21
-rw-r--r--src/web/views/api/v2/feed.py (renamed from src/web/views/api/feed.py)2
-rw-r--r--src/web/views/api/v3/__init__.py0
7 files changed, 20 insertions, 13 deletions
diff --git a/src/web/views/api/__init__.py b/src/web/views/api/__init__.py
index 458e031b..e69de29b 100644
--- a/src/web/views/api/__init__.py
+++ b/src/web/views/api/__init__.py
@@ -1,3 +0,0 @@
-from web.views.api import article, feed, category
-
-__all__ = ['article', 'feed', 'category']
diff --git a/src/web/views/api/v2/__init__.py b/src/web/views/api/v2/__init__.py
new file mode 100644
index 00000000..46760261
--- /dev/null
+++ b/src/web/views/api/v2/__init__.py
@@ -0,0 +1,3 @@
+from web.views.api.v2 import article, feed, category
+
+__all__ = ['article', 'feed', 'category']
diff --git a/src/web/views/api/article.py b/src/web/views/api/v2/article.py
index 5971f47d..71201538 100644
--- a/src/web/views/api/article.py
+++ b/src/web/views/api/v2/article.py
@@ -6,7 +6,7 @@ from flask.ext.restful import Api
from web.views.common import api_permission
from web.controllers import ArticleController
-from web.views.api.common import (PyAggAbstractResource,
+from web.views.api.v2.common import (PyAggAbstractResource,
PyAggResourceNew, PyAggResourceExisting, PyAggResourceMulti)
diff --git a/src/web/views/api/category.py b/src/web/views/api/v2/category.py
index eecfa785..21459fc5 100644
--- a/src/web/views/api/category.py
+++ b/src/web/views/api/v2/category.py
@@ -3,7 +3,7 @@ from flask import current_app
from flask.ext.restful import Api
from web.controllers.category import CategoryController
-from web.views.api.common import (PyAggResourceNew,
+from web.views.api.v2.common import (PyAggResourceNew,
PyAggResourceExisting,
PyAggResourceMulti)
diff --git a/src/web/views/api/common.py b/src/web/views/api/v2/common.py
index ace6ba3a..092b33b0 100644
--- a/src/web/views/api/common.py
+++ b/src/web/views/api/v2/common.py
@@ -18,6 +18,7 @@ routes :
DELETE resources
-> to delete several
"""
+import ast
import logging
from functools import wraps
from werkzeug.exceptions import Unauthorized, BadRequest, Forbidden, NotFound
@@ -97,7 +98,8 @@ class PyAggAbstractResource(Resource):
continue
else:
parser.add_argument(attr_name, location='json', **attr)
- return parser.parse_args(req=req, strict=strict)
+ #return parser.parse_args(req=req, strict=strict)
+ return attrs
class PyAggResourceNew(PyAggAbstractResource):
@@ -133,12 +135,20 @@ 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 = {}
try:
limit = request.json.pop('limit', 10)
order_by = request.json.pop('order_by', None)
- args = self.reqparse_args(right='read', default=False)
- except BadRequest:
- limit, order_by, args = 10, None, {}
+ except Exception:
+ attrs = self.reqparse_args(right='read', default=False)
+ for k, v in request.args.items():
+ if k in attrs.keys():
+ if 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)
@@ -152,7 +162,6 @@ class PyAggResourceMulti(PyAggAbstractResource):
>>> payload
[{attr1: val1, attr2: val2}, {attr1: val1, attr2: val2}]
"""
- assert 'application/json' in request.headers.get('Content-Type')
status, fail_count, results = 200, 0, []
class Proxy:
@@ -178,7 +187,6 @@ class PyAggResourceMulti(PyAggAbstractResource):
[[obj_id1, {attr1: val1, attr2: val2}]
[obj_id2, {attr1: val1, attr2: val2}]]
"""
- assert 'application/json' in request.headers.get('Content-Type')
status, results = 200, []
class Proxy:
@@ -203,7 +211,6 @@ class PyAggResourceMulti(PyAggAbstractResource):
def delete(self):
"""will delete several objects,
a list of their ids should be in the payload"""
- assert 'application/json' in request.headers.get('Content-Type')
status, results = 204, []
for obj_id in request.json:
try:
diff --git a/src/web/views/api/feed.py b/src/web/views/api/v2/feed.py
index 774bff5f..686dcd76 100644
--- a/src/web/views/api/feed.py
+++ b/src/web/views/api/v2/feed.py
@@ -8,7 +8,7 @@ from web.controllers.feed import (FeedController,
DEFAULT_LIMIT,
DEFAULT_REFRESH_RATE)
-from web.views.api.common import PyAggAbstractResource, \
+from web.views.api.v2.common import PyAggAbstractResource, \
PyAggResourceNew, \
PyAggResourceExisting, \
PyAggResourceMulti
diff --git a/src/web/views/api/v3/__init__.py b/src/web/views/api/v3/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/web/views/api/v3/__init__.py
bgstack15