diff options
Diffstat (limited to 'src/web')
-rw-r--r-- | src/web/forms.py | 3 | ||||
-rw-r--r-- | src/web/views/api/v3/__init__.py | 4 | ||||
-rw-r--r-- | src/web/views/api/v3/article.py | 35 | ||||
-rw-r--r-- | src/web/views/api/v3/common.py | 44 | ||||
-rw-r--r-- | src/web/views/api/v3/feed.py | 28 |
5 files changed, 109 insertions, 5 deletions
diff --git a/src/web/forms.py b/src/web/forms.py index 85980791..c0526512 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -4,7 +4,7 @@ # JARR - A Web based news aggregator. # Copyright (C) 2010-2016 Cédric Bonhomme - https://www.cedricbonhomme.org # -# For more information : http://github.com/JARR-aggregator/JARR/ +# 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 @@ -26,7 +26,6 @@ __revision__ = "$Date: 2015/05/06 $" __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "GPLv3" - from flask import flash, url_for, redirect from flask.ext.wtf import Form from flask.ext.babel import lazy_gettext 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 |