From 9715533ac83fe63df7a384cfd74cfad342b588b4 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 13 Apr 2015 08:58:42 +0200 Subject: It is now possible to sort articles by date (default) or by feed. --- pyaggr3g470r/templates/home.html | 4 ++-- pyaggr3g470r/views/views.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index e055b3e0..98b12e25 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -73,9 +73,9 @@ - {{ _('Feed') }} + {{ _('Feed') }} {{ _('Article') }} - {{ _('Date') }} + {{ _('Date') }} diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index eabf3ebf..1918b1b5 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -251,6 +251,7 @@ def home(favorites=False): feed_contr.read(error_count__gt=2)} filter_ = request.args.get('filter_', 'all' if favorites else 'unread') + sort_ = request.args.get('sort_', 'date') feed_id = int(request.args.get('feed', 0)) limit = request.args.get('limit', 1000) @@ -270,14 +271,17 @@ def home(favorites=False): limit = int(limit) articles = articles.limit(limit) - def gen_url(filter_=filter_, limit=limit, feed=feed_id): + def gen_url(filter_=filter_, sort_=sort_, limit=limit, feed=feed_id): return url_for('favorites' if favorites else 'home', - filter_=filter_, limit=limit, feed=feed) + filter_=filter_, sort_=sort_, limit=limit, feed=feed) articles = list(articles) if not articles and not favorites and feed_id: return redirect(gen_url(filter_='all')) + if sort_ == "feed": + articles.sort(key=lambda article: article.source.title) + return render_template('home.html', gen_url=gen_url, feed_id=feed_id, filter_=filter_, limit=limit, feeds=feeds, unread=unread, articles=articles, in_error=in_error, -- cgit