From c6cab56905a5a2b42a949d78ce68d92a57890d09 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 3 Nov 2013 00:47:53 +0100 Subject: Page for favorites articles. --- pyaggr3g470r/templates/favorites.html | 45 +++++++++++++++++++++-------------- pyaggr3g470r/views.py | 16 ++++++------- 2 files changed, 35 insertions(+), 26 deletions(-) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/templates/favorites.html b/pyaggr3g470r/templates/favorites.html index 0b912286..46842382 100644 --- a/pyaggr3g470r/templates/favorites.html +++ b/pyaggr3g470r/templates/favorites.html @@ -1,28 +1,37 @@ -{% extends "layout.html" %} + {% extends "layout.html" %} {% block content %}
- {% for feed in favorites %} -
+ {% for feed in feeds %} +
-

{{ feed }}

+

{{ feed.title }}

+
- {% for number in range(0, favorites[feed]|length-2, 3) %} -
-
-

{{ favorites[feed][number].title }}

-

{{ favorites[feed][number].date }}
-
-
-

{{ favorites[feed][number+1].title }}

-

{{ favorites[feed][number+1].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 %}
-
-

{{ favorites[feed][number+2].title }}

-

{{ favorites[feed][number+2].date }}
+ {% 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 %}
-
- {% endfor %} + {% endif %} {% endfor %}
{% endblock %} \ No newline at end of file diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index c390ddc0..d487c1ec 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -147,18 +147,18 @@ def articles(feed_id=None): user = models.User.objects(email=g.user.email, feeds__oid=feed_id).first() for feed in user.feeds: if str(feed.oid) == feed_id: - return render_template('articles.html', feed=user.feeds[0]) + return render_template('articles.html', feed=user.feeds) @app.route('/favorites/', methods=['GET']) @login_required def favorites(): - favorites = defaultdict(list) - for feed in models.Feed.objects(): - for article in feed.articles: - if article.like: - favorites[feed.title].append(article) - - return render_template('favorites.html', favorites=favorites) + user = models.User.objects(email=g.user.email).first() + result = [] + for feed in user.feeds: + feed.articles = [article for article in feed.articles if article.like] + if len(feed.articles) != 0: + result.append(feed) + return render_template('favorites.html', feeds=result) @app.route('/unread/', methods=['GET']) @login_required -- cgit