aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/templates/todo/topics.html24
-rw-r--r--app/views/packages/todo.py23
2 files changed, 42 insertions, 5 deletions
diff --git a/app/templates/todo/topics.html b/app/templates/todo/topics.html
index 74a9381..4236a40 100644
--- a/app/templates/todo/topics.html
+++ b/app/templates/todo/topics.html
@@ -8,10 +8,32 @@ Topics to be Added
<h1>Topics to be Added</h1>
<p>
- {{ total - (topics | count) }} / {{ total }} packages have been added.
+ {{ total - (topic_count) }} / {{ total }} packages have been added.
{{ topics | count }} remaining.
</p>
+ <form method="GET" action="{{ url_for('todo_topics_page') }}" class="my-4">
+ <input class="" name="q" type="text" placeholder="Search topics" value="{{ query or ''}}">
+ <input class="btn btn-secondary my-2 my-sm-0 mr-sm-2" type="submit" value="Search" />
+ </form>
+
{% from "macros/topics.html" import render_topics_table %}
{{ render_topics_table(topics) }}
+
+ <ul class="pagination mt-4">
+ <li class="page-item {% if not prev_url %}disabled{% endif %}">
+ <a class="page-link" {% if prev_url %}href="{{ prev_url }}"{% endif %}>&laquo;</a>
+ </li>
+ {% for n in range(1, page_max+1) %}
+ <li class="page-item {% if n == page %}active{% endif %}">
+ <a class="page-link"
+ href="{{ url_for('todo_topics_page', page=n) }}">
+ {{ n }}
+ </a>
+ </li>
+ {% endfor %}
+ <li class="page-item {% if not next_url %}disabled{% endif %}">
+ <a class="page-link" {% if next_url %}href="{{ next_url }}"{% endif %}>&raquo;</a>
+ </li>
+ </ul>
{% endblock %}
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)