From 2710670654dd543e5dc732049ebe779ca317ac74 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 31 Oct 2013 20:58:32 +0100 Subject: Improved templates: rendering of the list of articles --- pyaggr3g470r/templates/home.html | 34 +++++++++++++++++++++++----------- pyaggr3g470r/templates/unread.html | 34 +++++++++++++++++++++++----------- pyaggr3g470r/views.py | 11 +++++++---- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index 0344263f..bf17356f 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -8,18 +8,30 @@ - {% for number in range(0, feed.articles|length-2, 3) %} -
- {% for n in range(number, number+3) %} -
- {% if feed.articles[n].readed %}

{% else %}

{% endif %} - {{ feed.articles[n].title }}

- {% if feed.articles[n].readed %}

{% else %}{% endif %} -
{{ feed.articles[n].date }}
+ {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %} +
+ {% for n in range(number, number+3) %} +
+ {% if feed.articles[n].readed %}

{% else %}

{% endif %} + {{ feed.articles[n].title }}

+ {% if feed.articles[n].readed %}

{% else %}{% endif %} +
{{ feed.articles[n].date }}
+
+ {% endfor %}
- {% endfor %} -
- {% endfor %} + {% endfor %} + {% if feed.articles|length % 3 != 0 %} +
+ {% for n in range(0, feed.articles|length % 3) %} +
+ {% if feed.articles[n].readed %}

{% else %}

{% endif %} + {{ feed.articles[n].title }}

+ {% if feed.articles[n].readed %}

{% else %}{% endif %} +
{{ feed.articles[n].date }}
+
+ {% endfor %} +
+ {% endif %} {% endfor %}
{% endblock %} \ No newline at end of file diff --git a/pyaggr3g470r/templates/unread.html b/pyaggr3g470r/templates/unread.html index 0344263f..bf17356f 100644 --- a/pyaggr3g470r/templates/unread.html +++ b/pyaggr3g470r/templates/unread.html @@ -8,18 +8,30 @@ - {% for number in range(0, feed.articles|length-2, 3) %} -
- {% for n in range(number, number+3) %} -
- {% if feed.articles[n].readed %}

{% else %}

{% endif %} - {{ feed.articles[n].title }}

- {% if feed.articles[n].readed %}

{% else %}{% endif %} -
{{ feed.articles[n].date }}
+ {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %} +
+ {% for n in range(number, number+3) %} +
+ {% if feed.articles[n].readed %}

{% else %}

{% endif %} + {{ feed.articles[n].title }}

+ {% if feed.articles[n].readed %}

{% else %}{% endif %} +
{{ feed.articles[n].date }}
+
+ {% endfor %}
- {% endfor %} -
- {% endfor %} + {% endfor %} + {% if feed.articles|length % 3 != 0 %} +
+ {% for n in range(0, feed.articles|length % 3) %} +
+ {% if feed.articles[n].readed %}

{% else %}

{% endif %} + {{ feed.articles[n].title }}

+ {% if feed.articles[n].readed %}

{% else %}{% endif %} +
{{ feed.articles[n].date }}
+
+ {% endfor %} +
+ {% endif %} {% endfor %}
{% endblock %} \ No newline at end of file diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 359ae15d..fa406fe9 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -140,10 +140,13 @@ def favorites(): @app.route('/unread/', methods=['GET']) @login_required def unread(): - feeds = models.Feed.objects().filter(articles__readed=False) - unread_articles = models.Article.objects.filter(readed = False) - print len(feeds) - return render_template('unread.html', feeds=feeds) + feeds = models.Feed.objects() + result = [] + for feed in feeds: + feed.articles = [article for article in feed.articles if not article.readed] + if len(feed.articles) != 0: + result.append(feed) + return render_template('unread.html', feeds=result) @app.route('/management/', methods=['GET']) @login_required -- cgit