diff --git a/CTFd/admin/challenges.py b/CTFd/admin/challenges.py index b391b67f..c14d76ae 100644 --- a/CTFd/admin/challenges.py +++ b/CTFd/admin/challenges.py @@ -2,20 +2,41 @@ import os import six from flask import current_app as app -from flask import render_template, render_template_string, url_for +from flask import render_template, render_template_string, request, url_for from CTFd.admin import admin from CTFd.models import Challenges, Flags, Solves from CTFd.plugins.challenges import get_chal_class from CTFd.utils import binary_type from CTFd.utils.decorators import admins_only +from CTFd.utils.helpers import get_errors @admin.route("/admin/challenges") @admins_only def challenges_listing(): - challenges = Challenges.query.all() - return render_template("admin/challenges/challenges.html", challenges=challenges) + q = request.args.get("q") + if q: + field = request.args.get("field") + 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() + ) + return render_template( + "admin/challenges/challenges.html", challenges=challenges, q=q, field=field + ) + else: + challenges = Challenges.query.all() + return render_template( + "admin/challenges/challenges.html", challenges=challenges + ) @admin.route("/admin/challenges/") diff --git a/CTFd/themes/admin/templates/challenges/challenges.html b/CTFd/themes/admin/templates/challenges/challenges.html index 1fa73c9b..022173ff 100644 --- a/CTFd/themes/admin/templates/challenges/challenges.html +++ b/CTFd/themes/admin/templates/challenges/challenges.html @@ -18,6 +18,36 @@
+
+
+ {% if q and field %} +

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

+ {% endif %} + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +
+