mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Merge pull request #1340 from CTFd/1338-challenge-searching
* Copies basic challenge searching functionality from Users searching
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
|||||||
|
|
||||||
import six
|
import six
|
||||||
from flask import current_app as app
|
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.admin import admin
|
||||||
from CTFd.models import Challenges, Flags, Solves
|
from CTFd.models import Challenges, Flags, Solves
|
||||||
@@ -14,8 +14,25 @@ from CTFd.utils.decorators import admins_only
|
|||||||
@admin.route("/admin/challenges")
|
@admin.route("/admin/challenges")
|
||||||
@admins_only
|
@admins_only
|
||||||
def challenges_listing():
|
def challenges_listing():
|
||||||
challenges = Challenges.query.all()
|
q = request.args.get("q")
|
||||||
return render_template("admin/challenges/challenges.html", challenges=challenges)
|
field = request.args.get("field")
|
||||||
|
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()
|
||||||
|
return render_template(
|
||||||
|
"admin/challenges/challenges.html", challenges=challenges, q=q, field=field
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@admin.route("/admin/challenges/<int:challenge_id>")
|
@admin.route("/admin/challenges/<int:challenge_id>")
|
||||||
|
|||||||
@@ -18,6 +18,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{% if q and field %}
|
||||||
|
<h4 class="text-center">Searching for challenges with {{field}} matching {{q}}</h4>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form method="GET" class="form-inline">
|
||||||
|
<div class="form-group col-md-2">
|
||||||
|
<label for="sel1" class="sr-only" >Search Field</label>
|
||||||
|
<select class="form-control custom-select w-100" id="sel1" name="field">
|
||||||
|
<option value="name" {% if field == 'name' %}selected{% endif %}>Name</option>
|
||||||
|
<option value="id" {% if field == 'id' %}selected{% endif %}>ID</option>
|
||||||
|
<option value="category" {% if field == 'category' %}selected{% endif %}>Category</option>
|
||||||
|
<option value="type" {% if field == 'type' %}selected{% endif %}>Type</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-8">
|
||||||
|
<label for="team-name-search" class="sr-only">Parameter</label>
|
||||||
|
<input type="text" class="form-control w-100" id="team-name-search" name="q" placeholder="Search for matching challenge" {% if q %}value="{{q}}"{% endif %}>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-2">
|
||||||
|
<label for="team-name-search" class="sr-only">Search</label>
|
||||||
|
<button type="submit" class="btn btn-primary w-100"><i class="fas fa-search" aria-hidden="true"></i></button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="float-right pb-3">
|
<div class="float-right pb-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user