diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-12-23 18:03:23 +0000 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-12-23 18:04:56 +0000 |
commit | b8ca5d24c50f108ea574c89405e2ce2e70ea18af (patch) | |
tree | a46cc983a1ac42843c03ac8e8cec3ba6af05887e /app/views/packages/todo.py | |
parent | 63969529adf90a49916be56869ed4a63a9667e7c (diff) | |
download | cheatdb-b8ca5d24c50f108ea574c89405e2ce2e70ea18af.tar.xz |
Add pagination and search to topics
Diffstat (limited to 'app/views/packages/todo.py')
-rw-r--r-- | app/views/packages/todo.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/app/views/packages/todo.py b/app/views/packages/todo.py index 746ca61..596e83a 100644 --- a/app/views/packages/todo.py +++ b/app/views/packages/todo.py @@ -56,9 +56,24 @@ def todo_page(): def todo_topics_page(): total = ForumTopic.query.count() - topics = ForumTopic.query \ + query = ForumTopic.query \ .filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \ - .order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \ - .all() + .order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title)) - return render_template("todo/topics.html", topics=topics, total=total) + topic_count = query.count() + + search = request.args.get("q") + if search is not None and search.strip() != "": + query = query.filter(ForumTopic.title.ilike('%' + search + '%')) + + page = int(request.args.get("page") or 1) + num = min(100, int(request.args.get("n") or 100)) + query = query.paginate(page, num, True) + next_url = url_for("todo_topics_page", page=query.next_num) \ + if query.has_next else None + prev_url = url_for("todo_topics_page", page=query.prev_num) \ + if query.has_prev else None + + return render_template("todo/topics.html", topics=query.items, total=total, \ + topic_count=topic_count, query=search, \ + next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages) |