From dc96d2326411f45a0e1a14bdec2265821cceb65e Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Tue, 4 Aug 2015 10:49:42 +0200 Subject: making feeds/fetchable and articles/challenge returns 204 on empty --- pyaggr3g470r/views/api/article.py | 3 ++- pyaggr3g470r/views/api/feed.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/article.py b/pyaggr3g470r/views/api/article.py index 03ecdb18..d2969cb0 100644 --- a/pyaggr3g470r/views/api/article.py +++ b/pyaggr3g470r/views/api/article.py @@ -51,7 +51,8 @@ class ArticlesChallenge(PyAggAbstractResource): if key in id_dict: id_dict[key] = dateutil.parser.parse(id_dict[key]) - return self.wider_controller.challenge(parsed_args['ids']) + result = list(self.wider_controller.challenge(parsed_args['ids'])) + return result or None, 200 if result else 204 g.api.add_resource(ArticleNewAPI, '/article', endpoint='article_new.json') diff --git a/pyaggr3g470r/views/api/feed.py b/pyaggr3g470r/views/api/feed.py index 7d8cdf38..c80e9a9b 100644 --- a/pyaggr3g470r/views/api/feed.py +++ b/pyaggr3g470r/views/api/feed.py @@ -58,7 +58,8 @@ class FetchableFeedAPI(PyAggAbstractResource): contr = self.wider_controller else: contr = self.controller - return [feed for feed in contr.list_fetchable(**args)] + result = [feed for feed in contr.list_fetchable(**args)] + return result or None, 200 if result else 204 g.api.add_resource(FeedNewAPI, '/feed', endpoint='feed_new.json') -- cgit From d770bc17899b7e947252237e04a71075999c7f59 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Tue, 4 Aug 2015 18:17:10 +0200 Subject: refact feed list --- pyaggr3g470r/views/views.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 69c2b50b..560bd382 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -718,8 +718,10 @@ def create_user(user_id=None): user.activation_key = "" db.session.add(user) db.session.commit() - flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully created.'), 'success') - return redirect("/admin/edit_user/"+str(user.id)) + flash("%s %s %s" % (gettext('User'), user.nickname, + gettext('successfully created.')), + 'success') + return redirect(url_for('create_user', user_id=user.id)) else: return redirect(url_for('create_user')) @@ -727,11 +729,13 @@ def create_user(user_id=None): if user_id is not None: user = User.query.filter(User.id == user_id).first() form = UserForm(obj=user) - message = gettext('Edit the user') + ' ' + user.nickname + '' + message = "%s %s" % (gettext('Edit the user'), + user.nickname) else: form = UserForm() message = gettext('Add a new user') - return render_template('/admin/create_user.html', form=form, message=message) + return render_template('/admin/create_user.html', + form=form, message=message) @app.route('/admin/user/', methods=['GET']) @login_required @@ -743,10 +747,9 @@ def user(user_id=None): user = UserController().get(id=user_id) if user is not None: article_contr = ArticleController(user_id) - return render_template('/admin/user.html', user=user, + return render_template('/admin/user.html', user=user, feeds=user.feeds, article_count=article_contr.count_by_feed(), - unread_article_count=article_contr.count_by_feed(readed=False), - ) + unread_article_count=article_contr.count_by_feed(readed=False)) else: flash(gettext('This user does not exist.'), 'danger') -- cgit From 5e0aca072dc5ecb6a041f996e3b4ad5ef6d1205c Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Wed, 5 Aug 2015 16:05:29 +0200 Subject: making it easier to request with lists --- pyaggr3g470r/views/api/common.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index a7068807..acb5dd68 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -161,17 +161,17 @@ 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 """ - if 'application/json' not in request.headers.get('Content-Type'): - raise BadRequest("Content-Type must be application/json") - limit = 10 try: limit = request.json.pop('limit', 10) + order_by = request.json.pop('order_by', None) + query = self.controller.read(**request.json) except: - return [res for res in self.controller.read().limit(limit)] - if not limit: - return [res for res in self.controller.read(**request.json).all()] - return [res - for res in self.controller.read(**request.json).limit(limit)] + limit, order_by, query = 10, None, self.controller.read() + if order_by: + query = query.order_by(order_by) + if limit: + query = query.limit(limit) + return [res for res in query] def post(self): """creating several objects. payload should be a list of dict. -- cgit