From 48dfe7334e4879e5f57fe67e55cdf1f11cbfccc3 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 8 Apr 2014 20:00:18 +0200 Subject: /articles page is working. --- pyaggr3g470r/templates/articles.html | 16 ++++++++-------- pyaggr3g470r/views.py | 19 +++++++------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/pyaggr3g470r/templates/articles.html b/pyaggr3g470r/templates/articles.html index 97b06f6a..e50b12ec 100644 --- a/pyaggr3g470r/templates/articles.html +++ b/pyaggr3g470r/templates/articles.html @@ -3,18 +3,18 @@

{{ feed.title|safe }}

- - + + {% if nb_articles == -1 %} -

{{ feed.articles|count }} articles.

+

{{ feed.articles.all()|count }} articles.

{% else %} -

Last {{ feed.articles|count }} articles. See all articles.

+

Last {{ feed.articles.all()|count }} articles. See all articles.

{% endif %}
- {% if feed.articles|count == 0 %} + {% if feed.articles.all()|count == 0 %}

No articles.

{% else %} - {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %} + {% for number in range(0, feed.articles.all()|length-(feed.articles.all()|length % 3), 3) %}
{% for n in range(number, number+3) %}
@@ -26,9 +26,9 @@ {% endfor %}
{% endfor %} - {% if feed.articles|length % 3 != 0 %} + {% if feed.articles.all()|length % 3 != 0 %}
- {% for n in range(feed.articles|length-(feed.articles|length % 3), feed.articles|length) %} + {% for n in range(feed.articles.all()|length-(feed.articles.all()|length % 3), feed.articles.all()|length) %}
{% if feed.articles[n].readed %}

{% else %}

{% endif %} {{ feed.articles[n].title|safe }} diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 48220bb9..3f05c199 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -299,21 +299,16 @@ def delete(article_id=None): @app.route('/articles//', methods=['GET']) @login_required def articles(feed_id=None, nb_articles=-1): - try: - user = models.User.objects(email=g.user.email, feeds__oid=feed_id).first() - except: + feed = Feed.query.filter(Feed.id == feed_id).first() + if feed == None: flash("No such feed.", "danger") return redirect(url_for('home')) - for feed in user.feeds: - if str(feed.oid) == feed_id: - if len(feed.articles) <= nb_articles: - nb_articles = -1 - if nb_articles != -1: - feed.articles = feed.articles[0:nb_articles] - return render_template('articles.html', feed=feed, nb_articles=nb_articles) else: - flash("No such feed.", "error") - return redirect(url_for('home')) + if len(feed.articles.all()) <= nb_articles: + nb_articles = -1 + if nb_articles != -1: + feed.articles = feed.articles[0:nb_articles] + return render_template('articles.html', feed=feed, nb_articles=nb_articles) @app.route('/favorites/', methods=['GET']) @login_required -- cgit