mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 22:14:25 +01:00
Add basic challenge searching functionality
This commit is contained in:
@@ -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/<int:challenge_id>")
|
||||
|
||||
Reference in New Issue
Block a user