aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-14 08:14:52 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-14 08:14:52 +0200
commit728d34d05a47050262322148f1704dc075971863 (patch)
treef4bc2ae7a29a19abd9cdc3b790489c2e4cdf30a1 /src
parentRemoved links between current article and the previous/next articles. (diff)
parentBug fix: arguments in the URL weren't processed. (diff)
downloadnewspipe-728d34d05a47050262322148f1704dc075971863.tar.gz
newspipe-728d34d05a47050262322148f1704dc075971863.tar.bz2
newspipe-728d34d05a47050262322148f1704dc075971863.zip
Merge branch 'new-api'
Diffstat (limited to 'src')
-rw-r--r--src/web/views/__init__.py5
-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
8 files changed, 23 insertions, 15 deletions
diff --git a/src/web/views/__init__.py b/src/web/views/__init__.py
index 6de83818..4af8975b 100644
--- a/src/web/views/__init__.py
+++ b/src/web/views/__init__.py
@@ -1,4 +1,5 @@
-from web.views import views, home, session_mgmt, api
+from web.views.api import v2
+from web.views import views, home, session_mgmt
from web.views.article import article_bp, articles_bp
from web.views.feed import feed_bp, feeds_bp
from web.views.category import category_bp, categories_bp
@@ -6,7 +7,7 @@ from web.views.icon import icon_bp
from web.views.admin import admin_bp
from web.views.user import user_bp, users_bp
-__all__ = ['views', 'home', 'session_mgmt', 'api',
+__all__ = ['views', 'home', 'session_mgmt', 'v2',
'article_bp', 'articles_bp', 'feed_bp', 'feeds_bp',
'category_bp', 'categories_bp', 'icon_bp',
'admin_bp', 'user_bp', 'users_bp']
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