aboutsummaryrefslogtreecommitdiff
path: root/src/web/views/api/v3
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-29 07:39:19 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-29 07:39:19 +0200
commitee8c462bbeb3677b04fca4bd4ede0dd3d2b69393 (patch)
tree47ee2f87828c8c215a54717648d7e4cf05e4b40e /src/web/views/api/v3
parentImproved the Web services processors. (diff)
downloadnewspipe-ee8c462bbeb3677b04fca4bd4ede0dd3d2b69393.tar.gz
newspipe-ee8c462bbeb3677b04fca4bd4ede0dd3d2b69393.tar.bz2
newspipe-ee8c462bbeb3677b04fca4bd4ede0dd3d2b69393.zip
All preprocessors for the v3 Article Web service are implemented.
Diffstat (limited to 'src/web/views/api/v3')
-rw-r--r--src/web/views/api/v3/__init__.py4
-rw-r--r--src/web/views/api/v3/article.py35
-rw-r--r--src/web/views/api/v3/common.py44
-rw-r--r--src/web/views/api/v3/feed.py28
4 files changed, 108 insertions, 3 deletions
diff --git a/src/web/views/api/v3/__init__.py b/src/web/views/api/v3/__init__.py
index 04dd28ad..76aa1f19 100644
--- a/src/web/views/api/v3/__init__.py
+++ b/src/web/views/api/v3/__init__.py
@@ -1,3 +1,3 @@
-from web.views.api.v3 import article, feed
+from web.views.api.v3 import article
-__all__ = ['article', 'feed']
+__all__ = ['article']
diff --git a/src/web/views/api/v3/article.py b/src/web/views/api/v3/article.py
index 657a4af1..4f9bbb8b 100644
--- a/src/web/views/api/v3/article.py
+++ b/src/web/views/api/v3/article.py
@@ -1,3 +1,31 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# JARR - A Web based news aggregator.
+# Copyright (C) 2010-2016 Cédric Bonhomme - https://www.cedricbonhomme.org
+#
+# For more information : http://github.com/JARR/JARR
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 0.1 $"
+__date__ = "$Date: 2016/04/29 $"
+__revision__ = "$Date: 2016/04/29 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
from flask.ext.login import current_user
from werkzeug.exceptions import NotFound
from flask.ext.restless import ProcessingException
@@ -12,7 +40,10 @@ class ArticleProcessor(AbstractProcessor):
"""
def get_single_preprocessor(self, instance_id=None, **kw):
- article = ArticleController(current_user.id).get(id=instance_id)
+ try:
+ article = ArticleController(current_user.id).get(id=instance_id)
+ except NotFound:
+ raise ProcessingException(description='No such article.', code=404)
self.is_authorized(current_user, article)
def post_preprocessor(self, data=None, **kw):
@@ -46,6 +77,8 @@ blueprint_article = manager.create_api_blueprint(models.Article,
article_processor.post_preprocessor],
PUT_SINGLE=[auth_func,
article_processor.put_single_preprocessor],
+ PUT_MANY=[auth_func,
+ article_processor.put_many_preprocessor],
DELETE=[auth_func,
article_processor.delete_preprocessor]))
application.register_blueprint(blueprint_article)
diff --git a/src/web/views/api/v3/common.py b/src/web/views/api/v3/common.py
index 51e4e6be..05ce7057 100644
--- a/src/web/views/api/v3/common.py
+++ b/src/web/views/api/v3/common.py
@@ -1,3 +1,31 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# JARR - A Web based news aggregator.
+# Copyright (C) 2010-2016 Cédric Bonhomme - https://www.cedricbonhomme.org
+#
+# For more information : http://github.com/JARR/JARR
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 0.1 $"
+__date__ = "$Date: 2016/04/29 $"
+__revision__ = "$Date: 2016/04/29 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
from flask import request
from flask.ext.login import current_user
from flask.ext.restless import ProcessingException
@@ -61,5 +89,21 @@ class AbstractProcessor():
"""
pass
+ def put_many_preprocessor(search_params=None, data=None, **kw):
+ """Accepts two arguments: `search_params`, which is a dictionary
+ containing the search parameters for the request, and `data`, which
+ is a dictionary representing the fields to change on the matching
+ instances and the values to which they will be set.
+ """
+ filt = dict(name="user_id",
+ op="eq",
+ val=current_user.id)
+
+ # Check if there are any filters there already.
+ if "filters" not in search_params:
+ search_params["filters"] = []
+
+ search_params["filters"].append(filt)
+
def delete_preprocessor(self, instance_id=None, **kw):
pass
diff --git a/src/web/views/api/v3/feed.py b/src/web/views/api/v3/feed.py
index bf1d376f..1c32929f 100644
--- a/src/web/views/api/v3/feed.py
+++ b/src/web/views/api/v3/feed.py
@@ -1,3 +1,31 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# JARR - A Web based news aggregator.
+# Copyright (C) 2010-2016 Cédric Bonhomme - https://www.cedricbonhomme.org
+#
+# For more information : http://github.com/JARR/JARR
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 0.1 $"
+__date__ = "$Date: 2016/04/29 $"
+__revision__ = "$Date: 2016/04/29 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
from flask.ext.login import current_user
from web import models
from bootstrap import application, manager
bgstack15