diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2015-04-16 14:24:48 +0200 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2015-04-16 14:24:48 +0200 |
commit | edcfb221ecfec95ea824675863c5d76a45a585bd (patch) | |
tree | 3b60ee144d416c06b5f088e7efb31bf72b4f10d5 /pyaggr3g470r/views/views.py | |
parent | removing unused template (diff) | |
download | newspipe-edcfb221ecfec95ea824675863c5d76a45a585bd.tar.gz newspipe-edcfb221ecfec95ea824675863c5d76a45a585bd.tar.bz2 newspipe-edcfb221ecfec95ea824675863c5d76a45a585bd.zip |
redoing sorting on SQL and allowing to reverse sorting
Diffstat (limited to 'pyaggr3g470r/views/views.py')
-rw-r--r-- | pyaggr3g470r/views/views.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index c681a94d..c905c6e5 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -258,7 +258,13 @@ def render_home(filters={}, head_title='', page_to_render='home', **kwargs): head_title = "%s%s" % (feed_contr.get(id=feed_id).title, (' - %s' % head_title) if head_title else '') - articles = arti_contr.read(**filters).order_by(Article.date.desc()) + sort_param = {"feed": Article.title.desc(), + "date": Article.date.desc(), + "-feed": Article.title.asc(), + "-date": Article.date.asc(), + }.get(sort_, Article.date.desc()) + + articles = arti_contr.read(**filters).order_by(sort_param) if limit != 'all': limit = int(limit) articles = articles.limit(limit) @@ -277,13 +283,10 @@ def render_home(filters={}, head_title='', page_to_render='home', **kwargs): and filter_ != 'all' and not articles: 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, - head_title=head_title, **kwargs) + head_title=head_title, sort_=sort_, **kwargs) @app.route('/') |