diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2014-04-08 07:48:48 +0200 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2014-04-08 07:48:48 +0200 |
commit | f7fdfe946180db61802cd8c2cf88392ace1d78e4 (patch) | |
tree | 0fe1ed5e1bd10407a58d037088154bae781b0d55 /pyaggr3g470r/views.py | |
parent | Added decorator to check if a user has access to a feed. (diff) | |
download | newspipe-f7fdfe946180db61802cd8c2cf88392ace1d78e4.tar.gz newspipe-f7fdfe946180db61802cd8c2cf88392ace1d78e4.tar.bz2 newspipe-f7fdfe946180db61802cd8c2cf88392ace1d78e4.zip |
Management page near to be OK.
Diffstat (limited to 'pyaggr3g470r/views.py')
-rw-r--r-- | pyaggr3g470r/views.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 3a6f35d9..fb1e6429 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -103,10 +103,11 @@ def feed_access_required(func): @wraps(func) def decorated(*args, **kwargs): #print("Now calling %s with %s,%s" % (func, args, kwargs)) - feed = Feed.query.filter(Feed.id == kwargs['feed_id']).first() - if feed == None or feed.subscriber.id != g.user.id: - flash("This feed do not exist.", "danger") - return redirect(url_for('home')) + if kwargs.get('feed_id', None) != None: + feed = Feed.query.filter(Feed.id == kwargs.get('feed_id', None)).first() + if feed == None or feed.subscriber.id != g.user.id: + flash("This feed do not exist.", "danger") + return redirect(url_for('home')) return func(*args, **kwargs) return decorated @@ -467,12 +468,13 @@ def management(): form = AddFeedForm() - user = models.User.objects(email=g.user.email).first() - nb_feeds = len(user.feeds) + user = User.query.filter(User.id == g.user.id).first() + nb_feeds = len(user.feeds.all()) #nb_articles = sum([len(feed.articles) for feed in user.feeds]) #nb_unread_articles = sum([len([article for article in feed.articles if not article.readed]) for feed in user.feeds]) - nb_articles = models.Article.objects().count() - nb_unread_articles = models.Article.objects(readed=False).count() + #articles = Article.query.filter(Article.feed.subscriber.id == g.user.id).all() + nb_articles = sum([len(feed.articles.all()) for feed in user.feeds]) + nb_unread_articles = 2 return render_template('management.html', form=form, \ nb_feeds=nb_feeds, nb_articles=nb_articles, nb_unread_articles=nb_unread_articles) |