diff --git a/CTFd/admin/challenges.py b/CTFd/admin/challenges.py index ac132e4f..63547621 100644 --- a/CTFd/admin/challenges.py +++ b/CTFd/admin/challenges.py @@ -16,22 +16,23 @@ from CTFd.utils.decorators import admins_only def challenges_listing(): q = request.args.get("q") field = request.args.get("field") + filters = [] + if q: - challenges = [] - if Challenges.__mapper__.has_property( - field - ): # The field exists as an exposed column - challenges = ( - Challenges.query.filter( - getattr(Challenges, field).like("%{}%".format(q)) - ) - .order_by(Challenges.id.asc()) - .all() - ) - else: - challenges = Challenges.query.all() + # The field exists as an exposed column + if Challenges.__mapper__.has_property(field): + filters.append(getattr(Challenges, field).like("%{}%".format(q))) + + query = Challenges.query.filter(*filters).order_by(Challenges.id.asc()) + challenges = query.all() + total = query.count() + return render_template( - "admin/challenges/challenges.html", challenges=challenges, q=q, field=field + "admin/challenges/challenges.html", + challenges=challenges, + total=total, + q=q, + field=field, ) diff --git a/CTFd/themes/admin/templates/challenges/challenges.html b/CTFd/themes/admin/templates/challenges/challenges.html index 022173ff..92b1e365 100644 --- a/CTFd/themes/admin/templates/challenges/challenges.html +++ b/CTFd/themes/admin/templates/challenges/challenges.html @@ -21,7 +21,8 @@
{% if q and field %} -

Searching for challenges with {{field}} matching {{q}}

+
Searching for challenges with {{ field }} matching {{ q }}
+
{{ total }} results
{% endif %}
@@ -35,11 +36,11 @@
- - + +
- +