Adds basic search functionality for teams from the admin paenl (#278)

* Fixes #189, #251
selenium-screenshot-testing
Kevin Chung 2017-06-12 13:45:16 -04:00 committed by GitHub
parent 5fc6c59245
commit 7bdfbfdd7f
2 changed files with 50 additions and 0 deletions

View File

@ -13,6 +13,27 @@ admin_teams = Blueprint('admin_teams', __name__)
@admin_teams.route('/admin/teams/<int:page>')
@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)

View File

@ -101,6 +101,35 @@ input[type="checkbox"] { margin: 0px !important; position: relative; top: 5px; }
</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">&nbsp;</label>
<input type="submit" class="form-control btn btn-default" value="Search">
</div>
</form>
</div>
<table id="teamsboard" class="table table-striped">
<thead>
<tr>