From daded6d193433cb6f76d93a4ed3833131d70f597 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 25 Dec 2018 16:40:19 +0000 Subject: [PATCH] Add sort by option to topic list --- app/templates/todo/topics.html | 17 ++++++++++++++--- app/views/packages/todo.py | 9 +++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/templates/todo/topics.html b/app/templates/todo/topics.html index 2156e8d9..8b39b8e8 100644 --- a/app/templates/todo/topics.html +++ b/app/templates/todo/topics.html @@ -9,17 +9,28 @@ Topics to be Added {% if current_user.rank.atLeast(current_user.rank.EDITOR) %} {% if n >= 10000 %} + href="{{ url_for('todo_topics_page', q=query, show_discarded=show_discarded, n=100, sort=sort_by) }}"> Paginiated List {% else %} + href="{{ url_for('todo_topics_page', q=query, show_discarded=show_discarded, n=10000, sort=sort_by) }}"> Unlimited List {% endif %} {% endif %} - + {% if sort_by == "name" %} + + Sort by date + + {% else %} + + Sort by name + + {% endif %} + {% if not show_discarded %} Show {% else %} diff --git a/app/views/packages/todo.py b/app/views/packages/todo.py index baca0001..2742f6d2 100644 --- a/app/views/packages/todo.py +++ b/app/views/packages/todo.py @@ -63,7 +63,12 @@ def todo_topics_page(): total = query.count() query = query.filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \ - .order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title)) + + sort_by = request.args.get("sort") + if sort_by == "name": + query = query.order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title)) + elif sort_by is None or sort_by == "date": + query = query.order_by(db.asc(ForumTopic.created_at)) topic_count = query.count() @@ -85,4 +90,4 @@ def todo_topics_page(): return render_template("todo/topics.html", topics=query.items, total=total, \ topic_count=topic_count, query=search, show_discarded=show_discarded, \ next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages, \ - n=num) + n=num, sort_by=sort_by)