From 930226b2c588be81891d0170c1a4b62042ac53b0 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 5 Mar 2015 21:41:58 +0100 Subject: Bug fix: 'sqlalchemy.exc.DataError: (DataError) LIMIT must not be negative' when loading the page /articles/id --- pyaggr3g470r/views/article.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/article.py b/pyaggr3g470r/views/article.py index 66cc0f37..a209f888 100644 --- a/pyaggr3g470r/views/article.py +++ b/pyaggr3g470r/views/article.py @@ -18,10 +18,9 @@ def articles(feed_id=None, nb_articles=-1): feed.articles = controllers.ArticleController(g.user.id)\ .read(feed_id=feed.id)\ .order_by(desc("Article.date")) - if len(feed.articles.all()) <= nb_articles: - nb_articles = -1 - if nb_articles == -1: - feed.articles = feed.articles.limit(nb_articles) + if len(feed.articles.all()) <= nb_articles or nb_articles == -1: + nb_articles = int(1e9) + feed.articles = feed.articles.limit(nb_articles) return render_template('articles.html', feed=feed, nb_articles=nb_articles) -- cgit From c8c3b06168127b5c61f74c0e37300ebbe05f0224 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Fri, 6 Mar 2015 08:53:47 +0100 Subject: Feed GET HTTP resource accepts request with no json data (test). --- pyaggr3g470r/views/api/common.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index 48a0d0ac..bfdc7860 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -1,7 +1,7 @@ """For a given resources, classes in the module intend to create the following routes : GET resource/ - -> to retreive one + -> to retrieve one POST resource -> to create one PUT resource/ @@ -10,7 +10,7 @@ routes : -> to delete one GET resources - -> to retreive several + -> to retrieve several POST resources -> to create several PUT resources @@ -146,12 +146,16 @@ class PyAggResourceExisting(PyAggAbstractResource): class PyAggResourceMulti(PyAggAbstractResource): def get(self): - """retreive several objects. filters can be set in the payload on the + """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' != request.headers.get('Content-Type'): raise BadRequest("Content-Type must be application/json") - limit = request.json.pop('limit', 10) + limit = 10 + try: + limit = request.json.pop('limit', 10) + 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)] -- cgit From 2378de49ba37116c5bf93054fd6aed65fa44022a Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 8 Mar 2015 12:07:36 +0100 Subject: Moved duplicate() function in utils.py. Some minor cosmethic changes. --- pyaggr3g470r/views/api/article.py | 3 +++ pyaggr3g470r/views/api/common.py | 5 +++-- pyaggr3g470r/views/api/feed.py | 9 +++------ pyaggr3g470r/views/article.py | 3 +++ pyaggr3g470r/views/feed.py | 3 +++ pyaggr3g470r/views/views.py | 4 ++-- 6 files changed, 17 insertions(+), 10 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/article.py b/pyaggr3g470r/views/api/article.py index 17881412..c3ec2d34 100644 --- a/pyaggr3g470r/views/api/article.py +++ b/pyaggr3g470r/views/api/article.py @@ -1,3 +1,6 @@ +#! /usr/bin/env python +# -*- coding: utf-8 - + from flask import g import dateutil.parser diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index bfdc7860..856b4bb9 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -1,3 +1,6 @@ +#! /usr/bin/env python +# -*- coding: utf-8 - + """For a given resources, classes in the module intend to create the following routes : GET resource/ @@ -54,13 +57,11 @@ def authenticate(func): and user.activation_key == "": g.user = user logged_in = True - if logged_in: return func(*args, **kwargs) raise Unauthorized({'WWWAuthenticate': 'Basic realm="Login Required"'}) return wrapper - def to_response(func): """Will cast results of func as a result, and try to extract a status_code for the Response object""" diff --git a/pyaggr3g470r/views/api/feed.py b/pyaggr3g470r/views/api/feed.py index 0d83ea43..7d0e2862 100644 --- a/pyaggr3g470r/views/api/feed.py +++ b/pyaggr3g470r/views/api/feed.py @@ -1,3 +1,6 @@ +#! /usr/bin/env python +# -*- coding: utf-8 - + from flask import g from pyaggr3g470r.controllers.feed import FeedController, \ @@ -8,7 +11,6 @@ from pyaggr3g470r.views.api.common import PyAggAbstractResource, \ PyAggResourceExisting, \ PyAggResourceMulti - FEED_ATTRS = {'title': {'type': str}, 'description': {'type': str}, 'link': {'type': str}, @@ -20,25 +22,21 @@ FEED_ATTRS = {'title': {'type': str}, 'last_error': {'type': str}, 'error_count': {'type': int, 'default': 0}} - class FeedNewAPI(PyAggResourceNew): controller_cls = FeedController attrs = FEED_ATTRS to_date = ['date', 'last_retrieved'] - class FeedAPI(PyAggResourceExisting): controller_cls = FeedController attrs = FEED_ATTRS to_date = ['date', 'last_retrieved'] - class FeedsAPI(PyAggResourceMulti): controller_cls = FeedController attrs = FEED_ATTRS to_date = ['date', 'last_retrieved'] - class FetchableFeedAPI(PyAggAbstractResource): controller_cls = FeedController to_date = ['date', 'last_retrieved'] @@ -49,7 +47,6 @@ class FetchableFeedAPI(PyAggAbstractResource): return [feed for feed in self.controller.list_fetchable( **self.reqparse_args())] - g.api.add_resource(FeedNewAPI, '/feed', endpoint='feed_new.json') g.api.add_resource(FeedAPI, '/feed/', endpoint='feed.json') g.api.add_resource(FeedsAPI, '/feeds', endpoint='feeds.json') diff --git a/pyaggr3g470r/views/article.py b/pyaggr3g470r/views/article.py index a209f888..08c92686 100644 --- a/pyaggr3g470r/views/article.py +++ b/pyaggr3g470r/views/article.py @@ -1,3 +1,6 @@ +#! /usr/bin/env python +# -*- coding: utf-8 - + from flask import Blueprint, g, render_template, redirect from sqlalchemy import desc diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 2af502a7..2e39ee4b 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -1,3 +1,6 @@ +#! /usr/bin/env python +# -*- coding: utf-8 - + from datetime import datetime from flask import Blueprint, g, render_template diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 0f1f8765..9d368c42 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -47,7 +47,7 @@ from sqlalchemy.exc import IntegrityError from werkzeug import generate_password_hash import conf -from pyaggr3g470r import utils, notifications, export, duplicate +from pyaggr3g470r import utils, notifications, export from pyaggr3g470r.models import User, Feed, Article, Role from pyaggr3g470r.decorators import feed_access_required from pyaggr3g470r.forms import SignupForm, SigninForm, AddFeedForm, \ @@ -399,7 +399,7 @@ def duplicates(feed_id=None): """ feed = Feed.query.filter(Feed.user_id == g.user.id, Feed.id == feed_id).first() duplicates = [] - duplicates = duplicate.compare_documents(feed) + duplicates = utils.compare_documents(feed) return render_template('duplicates.html', duplicates=duplicates, feed=feed) @app.route('/index_database', methods=['GET']) -- cgit From c625360db0971d1e79b5e56ad6e6d13cbbe7a927 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 9 Mar 2015 13:18:23 +0100 Subject: Test --- pyaggr3g470r/views/views.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 9d368c42..cb984a9c 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -574,11 +574,15 @@ def edit_feed(feed_id=None): # Create a new feed existing_feed = [f for f in g.user.feeds if f.link == form.link.data] if len(existing_feed) == 0: + print("Test 1") new_feed = Feed(title=form.title.data, description="", link=form.link.data, \ site_link=form.site_link.data, enabled=form.enabled.data) + print("Test 2") g.user.feeds.append(new_feed) #user.feeds = sorted(user.feeds, key=lambda t: t.title.lower()) + print("Test 3") db.session.commit() + print("Test 4") flash(gettext('Feed successfully created.'), 'success') utils.fetch(g.user.id, Feed.query.filter(Feed.link == form.link.data).first().id) -- cgit From be6398ccfe9c57d0642a0ac8eb62dcae2b7b5d23 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 9 Mar 2015 13:30:42 +0100 Subject: Test --- pyaggr3g470r/views/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index cb984a9c..579d1e1b 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -581,7 +581,10 @@ def edit_feed(feed_id=None): g.user.feeds.append(new_feed) #user.feeds = sorted(user.feeds, key=lambda t: t.title.lower()) print("Test 3") - db.session.commit() + try: + db.session.commit() + except Ecxeption as e: + print(e) print("Test 4") flash(gettext('Feed successfully created.'), 'success') -- cgit From 7a3c694e4b62ea73df023fe8a675896bd70ce1e5 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 9 Mar 2015 13:35:33 +0100 Subject: Bug fix. --- pyaggr3g470r/views/views.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 579d1e1b..9d368c42 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -574,18 +574,11 @@ def edit_feed(feed_id=None): # Create a new feed existing_feed = [f for f in g.user.feeds if f.link == form.link.data] if len(existing_feed) == 0: - print("Test 1") new_feed = Feed(title=form.title.data, description="", link=form.link.data, \ site_link=form.site_link.data, enabled=form.enabled.data) - print("Test 2") g.user.feeds.append(new_feed) #user.feeds = sorted(user.feeds, key=lambda t: t.title.lower()) - print("Test 3") - try: - db.session.commit() - except Ecxeption as e: - print(e) - print("Test 4") + db.session.commit() flash(gettext('Feed successfully created.'), 'success') utils.fetch(g.user.id, Feed.query.filter(Feed.link == form.link.data).first().id) -- cgit From 9a1a50f7cb2f63071fe127a29fece79585ea4037 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 15 Mar 2015 17:20:38 +0100 Subject: pylint check --- pyaggr3g470r/views/api/common.py | 1 - pyaggr3g470r/views/views.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index 856b4bb9..b1b0cd73 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -24,7 +24,6 @@ routes : import json import logging import dateutil.parser -from copy import deepcopy from functools import wraps from werkzeug.exceptions import Unauthorized, BadRequest from flask import request, g, session, Response diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 9d368c42..88835068 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -27,14 +27,13 @@ __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "AGPLv3" import os -import json import string import random import hashlib import datetime from collections import namedtuple from bootstrap import application as app, db -from flask import render_template, request, flash, session, Response, \ +from flask import render_template, request, flash, session, \ url_for, redirect, g, current_app, make_response, jsonify from flask.ext.login import LoginManager, login_user, logout_user, \ login_required, current_user, AnonymousUserMixin -- cgit From fb5df6041fc7bf97429bfe689e26fdc08e7e307f Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 15 Mar 2015 23:59:14 +0100 Subject: A new test for the history page. --- pyaggr3g470r/views/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 88835068..b7ccf955 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -539,10 +539,13 @@ def management(): not_on_heroku = not conf.ON_HEROKU) @app.route('/history', methods=['GET']) -@login_required -def history(): - #user = User.query.filter(User.id == g.user.id).first() - return render_template('history.html') +@app.route('/history/', methods=['GET']) +@app.route('/history//', methods=['GET']) +def history(year=None, month=None): + articles_counter, articles = utils.history(year, month) + return render_template('history.html', articles_counter=articles_counter, + articles=articles, + year=year, month=month) @app.route('/bookmarklet', methods=['GET']) @app.route('/create_feed', methods=['GET', 'POST']) -- cgit From 17bf200599ec978d8833a22aac85a803395d5207 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 15 Mar 2015 23:59:56 +0100 Subject: forgot login required decorator --- pyaggr3g470r/views/views.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index b7ccf955..c6f0d3d0 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -541,6 +541,7 @@ def management(): @app.route('/history', methods=['GET']) @app.route('/history/', methods=['GET']) @app.route('/history//', methods=['GET']) +@login_required def history(year=None, month=None): articles_counter, articles = utils.history(year, month) return render_template('history.html', articles_counter=articles_counter, -- cgit From 8d0fea82761f2fdc1ea93687429990eefa851fc8 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 16 Mar 2015 07:22:52 +0100 Subject: Improvements and fixes for the history() function. --- pyaggr3g470r/views/views.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index c6f0d3d0..9aefd6b1 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -543,10 +543,11 @@ def management(): @app.route('/history//', methods=['GET']) @login_required def history(year=None, month=None): - articles_counter, articles = utils.history(year, month) - return render_template('history.html', articles_counter=articles_counter, - articles=articles, - year=year, month=month) + articles_counter, articles = utils.history(g.user.id, year, month) + return render_template('history.html', + articles_counter=articles_counter, + articles=articles, + year=year, month=month) @app.route('/bookmarklet', methods=['GET']) @app.route('/create_feed', methods=['GET', 'POST']) -- cgit From c94a05150f22d0fef073efdd1ef6f1debb51dbab Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 23 Mar 2015 19:21:30 +0100 Subject: Fixed a minor bug in the '/feed' page. --- pyaggr3g470r/views/feed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 2e39ee4b..4fe4e5da 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -3,6 +3,7 @@ from datetime import datetime from flask import Blueprint, g, render_template +from sqlalchemy import desc from pyaggr3g470r import controllers, utils from pyaggr3g470r.decorators import pyagg_default_decorator, \ @@ -25,9 +26,9 @@ def feed(feed_id=None): "Presents detailed information about a feed." feed = controllers.FeedController(g.user.id).get(id=feed_id) word_size = 6 - articles = controllers.ArticleController(g.user.id)\ - .read(feed_id=feed_id).all() - nb_articles = controllers.ArticleController(g.user.id).read().count() + articles = controllers.ArticleController(g.user.id) \ + .read(feed_id=feed_id) \ + .order_by(desc("Article.date")).all() top_words = utils.top_words(articles, n=50, size=int(word_size)) tag_cloud = utils.tag_cloud(top_words) @@ -49,5 +50,4 @@ def feed(feed_id=None): feed=feed, tag_cloud=tag_cloud, first_post_date=first_article, end_post_date=last_article, - nb_articles=nb_articles, average=average, delta=delta, elapsed=elapsed) -- cgit From 89ad1ea47e3feaee8525a25980e33f2a289c039a Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 23 Mar 2015 21:47:26 +0100 Subject: The manual retrieving of news is solely available for administrator, on the Heroku platform. --- pyaggr3g470r/views/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 9aefd6b1..dc6bfead 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -264,8 +264,12 @@ def fetch(feed_id=None): Triggers the download of news. News are downloaded in a separated process, mandatory for Heroku. """ - utils.fetch(g.user.id, feed_id) - flash(gettext("Downloading articles..."), 'info') + if not conf.ON_HEROKU or g.user.is_admin(): + utils.fetch(g.user.id, feed_id) + flash(gettext("Downloading articles..."), "info") + else: + flash(gettext("The manual retrieving of news is only available " + + "for administrator, on the Heroku platform."), "info") return redirect(redirect_url()) @app.route('/about', methods=['GET']) -- cgit From d1cbb124997166292eed2f7cfb25c82d82792226 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 28 Mar 2015 09:55:16 +0100 Subject: It is now possible to delete all duplicate articles with one request. --- pyaggr3g470r/views/api/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index b1b0cd73..424df960 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -205,7 +205,8 @@ class PyAggResourceMulti(PyAggAbstractResource): def delete(self): """will delete several objects, a list of their ids should be in the payload""" - if 'application/json' != request.headers.get('Content-Type'): + if 'application/json' not in request.headers.get('Content-Type'): + print(request.headers.get('Content-Type')) raise BadRequest("Content-Type must be application/json") status = 204 results = [] -- cgit From a7df1043c338ea106cb745abcec70a3ce4e879a1 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 28 Mar 2015 10:22:57 +0100 Subject: Test of the headers was to strict. --- pyaggr3g470r/views/api/common.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index 424df960..405d6b2c 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -149,7 +149,7 @@ 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' != request.headers.get('Content-Type'): + if 'application/json' not in request.headers.get('Content-Type'): raise BadRequest("Content-Type must be application/json") limit = 10 try: @@ -163,7 +163,7 @@ class PyAggResourceMulti(PyAggAbstractResource): def post(self): """creating several objects. payload should be a list of dict. """ - if 'application/json' != request.headers.get('Content-Type'): + if 'application/json' not int request.headers.get('Content-Type'): raise BadRequest("Content-Type must be application/json") status = 201 results = [] @@ -184,7 +184,7 @@ class PyAggResourceMulti(PyAggAbstractResource): [[obj_id1, {attr1: val1, attr2: val2}] [obj_id2, {attr1: val1, attr2: val2}]] """ - if 'application/json' != request.headers.get('Content-Type'): + if 'application/json' not in request.headers.get('Content-Type'): raise BadRequest("Content-Type must be application/json") status = 200 results = [] @@ -206,7 +206,6 @@ class PyAggResourceMulti(PyAggAbstractResource): """will delete several objects, a list of their ids should be in the payload""" if 'application/json' not in request.headers.get('Content-Type'): - print(request.headers.get('Content-Type')) raise BadRequest("Content-Type must be application/json") status = 204 results = [] -- cgit From 3bff51bc47e9c52de37773a2aad3c3682ab42704 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 28 Mar 2015 10:26:34 +0100 Subject: Typo... --- pyaggr3g470r/views/api/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py index 405d6b2c..b8477d4b 100644 --- a/pyaggr3g470r/views/api/common.py +++ b/pyaggr3g470r/views/api/common.py @@ -163,7 +163,7 @@ class PyAggResourceMulti(PyAggAbstractResource): def post(self): """creating several objects. payload should be a list of dict. """ - if 'application/json' not int request.headers.get('Content-Type'): + if 'application/json' not in request.headers.get('Content-Type'): raise BadRequest("Content-Type must be application/json") status = 201 results = [] -- cgit From 3de4282a367b758d8bfcdfbfdd1cb995c283f213 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 29 Mar 2015 00:08:01 +0100 Subject: Use more the controllers in views.py. user_id_key is the email. --- pyaggr3g470r/views/views.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index dc6bfead..f77bdeba 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -47,6 +47,7 @@ from werkzeug import generate_password_hash import conf from pyaggr3g470r import utils, notifications, export +from pyaggr3g470r import controllers from pyaggr3g470r.models import User, Feed, Article, Role from pyaggr3g470r.decorators import feed_access_required from pyaggr3g470r.forms import SignupForm, SigninForm, AddFeedForm, \ @@ -92,7 +93,7 @@ def before_request(): @login_manager.user_loader def load_user(email): # Return an instance of the User model - return User.query.filter(User.email == email).first() + return controllers.UserController(email).get(email=email) # @@ -152,7 +153,7 @@ def login(): form = SigninForm() if form.validate_on_submit(): - user = User.query.filter(User.email == form.email.data).first() + user = controllers.UserController(form.email.data).get(email=form.email.data) login_user(user) g.user = user session['email'] = form.email.data @@ -381,7 +382,7 @@ def inactives(): List of inactive feeds. """ nb_days = int(request.args.get('nb_days', 365)) - user = User.query.filter(User.id == g.user.id).first() + user = controllers.UserController(g.user.email).get(email=g.user.email) today = datetime.datetime.now() inactives = [] for feed in user.feeds: @@ -428,7 +429,7 @@ def export_articles(): """ Export all articles to HTML or JSON. """ - user = User.query.filter(User.id == g.user.id).first() + user = controllers.UserController(g.user.email).get(id=g.user.id) if request.args.get('format') == "HTML": # Export to HTML try: @@ -460,7 +461,7 @@ def export_opml(): """ Export all feeds to OPML. """ - user = User.query.filter(User.id == g.user.id).first() + user = controllers.UserController(g.user.email).get(id=g.user.id) response = make_response(render_template('opml.xml', user=user, now=datetime.datetime.now())) response.headers['Content-Type'] = 'application/xml' response.headers['Content-Disposition'] = 'attachment; filename=feeds.opml' @@ -636,7 +637,7 @@ def profile(): """ Edit the profile of the currently logged user. """ - user = User.query.filter(User.email == g.user.email).first() + user = controllers.UserController(g.user.email).get(id=g.user.id) form = ProfileForm() if request.method == 'POST': @@ -662,7 +663,7 @@ def delete_account(): """ Delete the account of the user (with all its data). """ - user = User.query.filter(User.email == g.user.email).first() + user = controllers.UserController(g.user.email).get(id=g.user.id) if user is not None: db.session.delete(user) db.session.commit() -- cgit From 854862e1c73bf0c521e08b8973721e8be7aeb82e Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 1 Apr 2015 22:57:15 +0200 Subject: Bugfix. --- pyaggr3g470r/views/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index f77bdeba..3b39e9b0 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -510,7 +510,7 @@ def management(): if None != request.files.get('opmlfile', None): # Import an OPML file data = request.files.get('opmlfile', None) - if not g.allowed_file(data.filename): + if not utils.allowed_file(data.filename): flash(gettext('File not allowed.'), 'danger') else: try: @@ -523,7 +523,7 @@ def management(): elif None != request.files.get('jsonfile', None): # Import an account data = request.files.get('jsonfile', None) - if not g.allowed_file(data.filename): + if not utils.allowed_file(data.filename): flash(gettext('File not allowed.'), 'danger') else: try: -- cgit