From 1b50120f823f493a0ab02cd25b099b7b786bf20c Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 2 Feb 2014 10:14:09 +0100 Subject: Mark all articles as read by feed. --- pyaggr3g470r/templates/home.html | 1 + pyaggr3g470r/templates/unread.html | 1 + pyaggr3g470r/views.py | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index 9ea8c01a..25cb5012 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -14,6 +14,7 @@ {% if feed.enabled %} {% endif %} + {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %} diff --git a/pyaggr3g470r/templates/unread.html b/pyaggr3g470r/templates/unread.html index 41c89a29..9058182c 100644 --- a/pyaggr3g470r/templates/unread.html +++ b/pyaggr3g470r/templates/unread.html @@ -16,6 +16,7 @@ +

{{ feed.articles|length }} unread articles.

diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 78508179..ee163099 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -178,13 +178,22 @@ def article(article_id=None): return render_template('article.html', head_title=utils.clear_string(article.title), article=article) @app.route('/mark_as_read/', methods=['GET']) +@app.route('/mark_as_read/', methods=['GET']) @login_required -def mark_as_read(): +def mark_as_read(feed_id=None): """ Mark all unreaded articles as read. """ - #user = models.User.objects(email=g.user.email).first() - models.Article.objects(readed=False).update(set__readed=True) + if feed_id != None: + user = models.User.objects(email=g.user.email).first() + for feed in user.feeds: + if str(feed.oid) == feed_id: + unread_articles = [article for article in feed.articles if not article.readed] + for article in unread_articles: + article.readed = True + article.save() + else: + models.Article.objects(readed=False).update(set__readed=True) return redirect(url_for('home')) @app.route('/like/', methods=['GET']) -- cgit