mirror of https://github.com/JohnHammond/CTFd.git
Adds basic search functionality for teams from the admin paenl (#278)
* Fixes #189, #251selenium-screenshot-testing
parent
5fc6c59245
commit
7bdfbfdd7f
|
@ -13,6 +13,27 @@ admin_teams = Blueprint('admin_teams', __name__)
|
||||||
@admin_teams.route('/admin/teams/<int:page>')
|
@admin_teams.route('/admin/teams/<int:page>')
|
||||||
@admins_only
|
@admins_only
|
||||||
def admin_teams_view(page):
|
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))
|
page = abs(int(page))
|
||||||
results_per_page = 50
|
results_per_page = 50
|
||||||
page_start = results_per_page * (page - 1)
|
page_start = results_per_page * (page - 1)
|
||||||
|
|
|
@ -101,6 +101,35 @@ input[type="checkbox"] { margin: 0px !important; position: relative; top: 5px; }
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if q and field%}
|
||||||
|
<h4 class="text-center">Searching for teams with {{field}} matching {{q}}</h4>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<form method="GET">
|
||||||
|
<div class="col-md-2 form-group">
|
||||||
|
<label for="sel1">Search Field</label>
|
||||||
|
<select name="field" class="form-control" id="sel1">
|
||||||
|
<option value="id" {% if field == 'id' %}selected{% endif %}>ID</option>
|
||||||
|
<option value="name" {% if field == 'name' %}selected{% endif %}>Name</option>
|
||||||
|
<option value="email" {% if field == 'email' %}selected{% endif %}>Email</option>
|
||||||
|
<option value="affiliation" {% if field == 'affiliation' %}selected{% endif %}>Affiliation</option>
|
||||||
|
<option value="country" {% if field == 'country' %}selected{% endif %}>Country</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8 form-group">
|
||||||
|
<label for="team-name-search">Parameter</label>
|
||||||
|
<input type="text" class="form-control" id="team-name-search" name="q" placeholder="Search for matching team names" {% if q %}value="{{q}}"{% endif %}>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2 form-group">
|
||||||
|
<label for="team-name-search"> </label>
|
||||||
|
<input type="submit" class="form-control btn btn-default" value="Search">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<table id="teamsboard" class="table table-striped">
|
<table id="teamsboard" class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in New Issue