diff options
-rw-r--r-- | pyaggr3g470r/controllers/article.py | 9 | ||||
-rw-r--r-- | pyaggr3g470r/templates/feeds.html | 2 | ||||
-rw-r--r-- | pyaggr3g470r/views/feed.py | 3 | ||||
-rw-r--r-- | pyaggr3g470r/views/views.py | 2 | ||||
-rw-r--r-- | tests/controllers/article.py | 4 |
5 files changed, 11 insertions, 9 deletions
diff --git a/pyaggr3g470r/controllers/article.py b/pyaggr3g470r/controllers/article.py index b3a79838..70b9d2dd 100644 --- a/pyaggr3g470r/controllers/article.py +++ b/pyaggr3g470r/controllers/article.py @@ -26,11 +26,12 @@ class ArticleController(AbstractController): continue yield id_ - def get_unread(self): + def count_by_feed(self, **filters): + if self.user_id: + filters['user_id'] = self.user_id return dict(db.session.query(Article.feed_id, func.count(Article.id)) - .filter(*self._to_filters(readed=False, - user_id=self.user_id)) - .group_by(Article.feed_id).all()) + .filter(*self._to_filters(**filters)) + .group_by(Article.feed_id).all()) def create(self, **attrs): # handling special denorm for article rights diff --git a/pyaggr3g470r/templates/feeds.html b/pyaggr3g470r/templates/feeds.html index f0e674c9..4d4581d4 100644 --- a/pyaggr3g470r/templates/feeds.html +++ b/pyaggr3g470r/templates/feeds.html @@ -30,7 +30,7 @@ </td> <td><a href="{{ url_for("feed.feed", feed_id=feed.id) }}" {% if feed.description %}title="{{ feed.description }}"{% endif %}>{{ feed.title }}</a></td> <td><a href="{{ feed.site_link }}">{{ feed.site_link }}</a></td> - <td>{{ feed.articles.count() }}</td> + <td>{{ article_count[feed.id] }}</td> <td> <a href="{{ url_for("home", feed_id=feed.id, filter_="all") }}"><i class="glyphicon glyphicon-th-list" title="{{ _('Articles') }}"></i></a> <a href="{{ url_for("feed.form", feed_id=feed.id) }}"><i class="glyphicon glyphicon-edit" title="{{ _('Edit this feed') }}"></i></a> diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 51832ea5..f940e22d 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -24,7 +24,8 @@ feed_bp = Blueprint('feed', __name__, url_prefix='/feed') def feeds(): "Lists the subscribed feeds in a table." return render_template('feeds.html', - feeds=FeedController(g.user.id).read()) + feeds=FeedController(g.user.id).read(), + article_count=ArticleController(g.user.id).count_by_feed()) @feed_bp.route('/<int:feed_id>', methods=['GET']) diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 77f3b147..e0bd1dcb 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -246,7 +246,7 @@ def render_home(filters=None, head_titles=None, arti_contr = ArticleController(g.user.id) feeds = {feed.id: feed.title for feed in feed_contr.read()} - unread = arti_contr.get_unread() + unread = arti_contr.count_by_feed(readed=False) in_error = {feed.id: feed.error_count for feed in feed_contr.read(error_count__gt=2)} diff --git a/tests/controllers/article.py b/tests/controllers/article.py index 5e873694..5a54e0b7 100644 --- a/tests/controllers/article.py +++ b/tests/controllers/article.py @@ -23,9 +23,9 @@ class ArticleControllerTest(BasePyaggTest): def test_article_get_unread(self): self.assertEquals({1: 3, 2: 3, 3: 3}, - ArticleController(2).get_unread()) + ArticleController(2).count_by_feed(readed=False)) self.assertEquals({4: 3, 5: 3, 6: 3}, - ArticleController(3).get_unread()) + ArticleController(3).count_by_feed(readed=False)) def test_create_using_filters(self): feed_ctr = FeedController(2) |