From 839a767c8cef256b28a85567a96b7f8d2a7a5192 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 27 Apr 2020 16:40:58 -0400 Subject: [PATCH 1/3] Show search results on challenge search --- CTFd/admin/challenges.py | 30 ++++++++++--------- .../templates/challenges/challenges.html | 3 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CTFd/admin/challenges.py b/CTFd/admin/challenges.py index ac132e4f..d1ccd402 100644 --- a/CTFd/admin/challenges.py +++ b/CTFd/admin/challenges.py @@ -3,6 +3,7 @@ import os import six from flask import current_app as app from flask import render_template, render_template_string, request, url_for +from flask_sqlalchemy import Pagination from CTFd.admin import admin from CTFd.models import Challenges, Flags, Solves @@ -16,22 +17,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..8960998c 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 %}
From 48bcd76a86f884f2f8da1ab2ed5b8e5d4be03cac Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 27 Apr 2020 16:59:00 -0400 Subject: [PATCH 2/3] Clean up HTML IDs --- CTFd/themes/admin/templates/challenges/challenges.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CTFd/themes/admin/templates/challenges/challenges.html b/CTFd/themes/admin/templates/challenges/challenges.html index 8960998c..92b1e365 100644 --- a/CTFd/themes/admin/templates/challenges/challenges.html +++ b/CTFd/themes/admin/templates/challenges/challenges.html @@ -36,11 +36,11 @@
- - + +
- +
From 77af80b5381590bcbe0fa3b134264675bc5dc744 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 27 Apr 2020 20:13:12 -0400 Subject: [PATCH 3/3] Run make lint --- CTFd/admin/challenges.py | 1 - 1 file changed, 1 deletion(-) diff --git a/CTFd/admin/challenges.py b/CTFd/admin/challenges.py index d1ccd402..63547621 100644 --- a/CTFd/admin/challenges.py +++ b/CTFd/admin/challenges.py @@ -3,7 +3,6 @@ import os import six from flask import current_app as app from flask import render_template, render_template_string, request, url_for -from flask_sqlalchemy import Pagination from CTFd.admin import admin from CTFd.models import Challenges, Flags, Solves