From cb6a8d8b53bb27755eb9bc040f86a361636d4c6a Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Sun, 8 Jun 2014 17:47:42 +0200 Subject: adding the capacity to mark articles as unread --- pyaggr3g470r/templates/article.html | 1 + pyaggr3g470r/templates/home.html | 5 +++-- pyaggr3g470r/templates/layout.html | 4 ++-- pyaggr3g470r/templates/unread.html | 3 ++- pyaggr3g470r/views.py | 26 +++++++++++++++++--------- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/pyaggr3g470r/templates/article.html b/pyaggr3g470r/templates/article.html index 83e23b34..1ee86948 100644 --- a/pyaggr3g470r/templates/article.html +++ b/pyaggr3g470r/templates/article.html @@ -14,6 +14,7 @@ {% else %} {% endif %} +
{{ article.date | datetime }}
diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index c1663997..297e0214 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -25,7 +25,7 @@

{{ feed.title|safe }} {% if feed.nb_unread != 0 %} - {{ feed.nb_unread }} + {{ feed.nb_unread }} {% endif %}

@@ -34,8 +34,9 @@ {% endif %} {% if feed.nb_unread != 0 %} - + {% endif %} +
{% for number in range(0, feed.articles.all()|count-(feed.articles.all()|count % 3), 3) %} diff --git a/pyaggr3g470r/templates/layout.html b/pyaggr3g470r/templates/layout.html index d1040422..8fc88d74 100644 --- a/pyaggr3g470r/templates/layout.html +++ b/pyaggr3g470r/templates/layout.html @@ -27,7 +27,7 @@ deployed on Heroku or on a traditional server." /> height: 0; } ul.affix { - position: fixed; + position: fixed; top: 0px; } ul.affix-top { @@ -102,7 +102,7 @@ deployed on Heroku or on a traditional server." /> {{ _('Articles') }} diff --git a/pyaggr3g470r/templates/unread.html b/pyaggr3g470r/templates/unread.html index 6c5c5d08..cdfb0dfe 100644 --- a/pyaggr3g470r/templates/unread.html +++ b/pyaggr3g470r/templates/unread.html @@ -16,7 +16,8 @@ - + +

{{ feed.articles.all()|length }} {{ _('unread articles') }}.

diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index e4668f54..1f3e16d7 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -312,23 +312,31 @@ def article(article_id=None): return redirect(redirect_url()) -@app.route('/mark_as_read/', methods=['GET']) -@app.route('/mark_as_read/', methods=['GET']) +@app.route('/mark_as/', methods=['GET']) +@app.route('/mark_as//feed/', methods=['GET']) +@app.route('/mark_as//article/', methods=['GET']) @login_required @feed_access_required -def mark_as_read(feed_id=None): +def mark_as(new_value='read', feed_id=None, article_id=None): """ Mark all unreaded articles as read. """ + readed = new_value == 'read' + articles = Article.query.filter(Article.user_id == g.user.id) if feed_id is not None: - Article.query.filter(Article.user_id == g.user.id, Article.feed_id == feed_id, - Article.readed == False).update({"readed": True}) - flash(gettext('Articles marked as read.'), 'info') + articles = articles.filter(Article.feed_id == feed_id) + message = 'Feed marked as %s.' + elif article_id is not None: + articles = articles.filter(Article.id == article_id) + message = 'Article marked as %s.' else: - Article.query.filter(Article.user_id == g.user.id, Article.readed == False).update({"readed": True}) - flash(gettext("All articles marked as read"), 'info') + message = 'All article marked as %s.' + articles.filter(Article.readed == (not readed)).update({"readed": readed}) + flash(gettext(message % new_value), 'info') db.session.commit() - return redirect(redirect_url()) + if readed: + return redirect(redirect_url()) + return redirect('/#%d' % articles.first().feed_id) @app.route('/like/', methods=['GET']) @login_required -- cgit