mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 22:14:25 +01:00
Show search results on challenge search
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user