From be33517445c787be0da5577da048d4b2d91452d4 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Thu, 28 May 2015 15:27:21 +0200 Subject: adding unread count when listing feeds, using count_by_feed for user management --- pyaggr3g470r/templates/admin/user.html | 4 ++-- pyaggr3g470r/templates/feeds.html | 2 +- pyaggr3g470r/views/feed.py | 5 ++++- pyaggr3g470r/views/views.py | 9 +++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pyaggr3g470r/templates/admin/user.html b/pyaggr3g470r/templates/admin/user.html index 317fef49..e50741ee 100644 --- a/pyaggr3g470r/templates/admin/user.html +++ b/pyaggr3g470r/templates/admin/user.html @@ -26,7 +26,7 @@ {{ _('Name') }} {{ _('Feed link') }} {{ _('Site link') }} - {{ _('Number of articles') }} + {{ _('(unread) articles') }} {{ _('Actions') }} @@ -37,7 +37,7 @@ {{ feed.title }} {{ feed.link }} {{ feed.site_link }} - {{ feed.articles.all()|count }} + ( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }} diff --git a/pyaggr3g470r/templates/feeds.html b/pyaggr3g470r/templates/feeds.html index 4d4581d4..789decf5 100644 --- a/pyaggr3g470r/templates/feeds.html +++ b/pyaggr3g470r/templates/feeds.html @@ -30,7 +30,7 @@ {{ feed.title }} {{ feed.site_link }} - {{ article_count[feed.id] }} + ( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }} diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index f940e22d..d50d0883 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -23,9 +23,12 @@ feed_bp = Blueprint('feed', __name__, url_prefix='/feed') @login_required def feeds(): "Lists the subscribed feeds in a table." + art_contr = ArticleController(g.user.id) return render_template('feeds.html', feeds=FeedController(g.user.id).read(), - article_count=ArticleController(g.user.id).count_by_feed()) + unread_article_count=art_contr.count_by_feed(readed=False), + article_count=art_contr.count_by_feed(), + ) @feed_bp.route('/', methods=['GET']) diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index e0bd1dcb..a4e799cc 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -736,9 +736,14 @@ def user(user_id=None): """ See information about a user (stations, etc.). """ - user = User.query.filter(User.id == user_id).first() + user = UserController().get(id=user_id) if user is not None: - return render_template('/admin/user.html', user=user) + article_contr = ArticleController(user_id) + return render_template('/admin/user.html', user=user, + article_count=article_contr.count_by_feed(), + unread_article_count=article_contr.count_by_feed(readed=False), + ) + else: flash(gettext('This user does not exist.'), 'danger') return redirect(redirect_url()) -- cgit