mirror of https://github.com/JohnHammond/CTFd.git
Show search results on challenge search
parent
b8b14a568e
commit
839a767c8c
|
@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{% if q and field %}
|
||||
<h4 class="text-center">Searching for challenges with {{field}} matching {{q}}</h4>
|
||||
<h5 class="text-muted text-center">Searching for challenges with <strong>{{ field }}</strong> matching <strong>{{ q }}</strong></h5>
|
||||
<h6 class="text-muted text-center pb-3">{{ total }} results</h6>
|
||||
{% endif %}
|
||||
|
||||
<form method="GET" class="form-inline">
|
||||
|
|
Loading…
Reference in New Issue