From 7bdfbfdd7fc0a285de1e82c54f218dfd98dec2ef Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 12 Jun 2017 13:45:16 -0400 Subject: [PATCH] Adds basic search functionality for teams from the admin paenl (#278) * Fixes #189, #251 --- CTFd/admin/teams.py | 21 +++++++++++++++++++++ CTFd/templates/admin/teams.html | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/CTFd/admin/teams.py b/CTFd/admin/teams.py index dca6fd10..a449f668 100644 --- a/CTFd/admin/teams.py +++ b/CTFd/admin/teams.py @@ -13,6 +13,27 @@ admin_teams = Blueprint('admin_teams', __name__) @admin_teams.route('/admin/teams/') @admins_only def admin_teams_view(page): + q = request.args.get('q') + if q: + field = request.args.get('field') + teams = [] + errors = [] + if field == 'id': + if q.isnumeric(): + teams = Teams.query.filter(Teams.id == q).order_by(Teams.id.asc()).all() + else: + teams = [] + errors.append('Your ID search term is not numeric') + elif field == 'name': + teams = Teams.query.filter(Teams.name.like('%{}%'.format(q))).order_by(Teams.id.asc()).all() + elif field == 'email': + teams = Teams.query.filter(Teams.email.like('%{}%'.format(q))).order_by(Teams.id.asc()).all() + elif field == 'affiliation': + teams = Teams.query.filter(Teams.affiliation.like('%{}%'.format(q))).order_by(Teams.id.asc()).all() + elif field == 'country': + teams = Teams.query.filter(Teams.country.like('%{}%'.format(q))).order_by(Teams.id.asc()).all() + return render_template('admin/teams.html', teams=teams, pages=None, curr_page=None, q=q, field=field) + page = abs(int(page)) results_per_page = 50 page_start = results_per_page * (page - 1) diff --git a/CTFd/templates/admin/teams.html b/CTFd/templates/admin/teams.html index 7fc2f713..f39b0511 100644 --- a/CTFd/templates/admin/teams.html +++ b/CTFd/templates/admin/teams.html @@ -101,6 +101,35 @@ input[type="checkbox"] { margin: 0px !important; position: relative; top: 5px; } + + {% if q and field%} +

Searching for teams with {{field}} matching {{q}}

+ {% endif %} + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +