Filters save state in expert browser

This commit is contained in:
Zakary Timson 2017-10-02 15:41:05 -04:00
parent faf1a9d0ed
commit b0cbc63db5
2 changed files with 38 additions and 34 deletions

View File

@ -4,6 +4,34 @@
<div class="container-fluid" style="background-color: #001f2f">
<div class="container">
<div class="row">
<div class="col-md-3 bg-dark-primary">
<h4 class="mt-3 pl-1 text-white">Filters:</h4>
<form>
<div class="mt-2">
<h5 for="filter" class="text-white mb-0 pl-1">Name</h5>
<input class="form-control" name="name" value="{{ name }}">
</div>
<div class="mt-2">
<h5 for="filter" class="text-white mb-0 pl-1">Institute</h5>
<select id="filter" class="form-control" name="institute">
<option selected></option>
{% for i in institutes %}
<option {% if i == institute %}selected{% endif %}>{{ i }}</option>
{% endfor %}
</select>
</div>
<div class="mt-2">
<h5 for="filter" class="text-white mb-0 pl-1">Areas of Expertise</h5>
<select id="filter" class="form-control" name="expertise">
<option selected></option>
{% for a in aoe %}
<option {% if a.field == expertise %}selected{% endif %}>{{ a.field }}</option>
{% endfor %}
</select>
</div>
<button class="btn btn-primary float-right my-3">Search</button>
</form>
</div>
<div class="col-md-9 bg-light-blue">
<div class="bg-white my-3">
{% for expert in experts %}
@ -23,34 +51,6 @@
{% endfor %}
</div>
</div>
<div class="col-md-3 bg-dark-primary">
<h4 class="mt-3 pl-1 text-white">Filters:</h4>
<form>
<div class="mt-2">
<h5 for="filter" class="text-white mb-0 pl-1">Name</h5>
<input class="form-control" name="name">
</div>
<div class="mt-2">
<h5 for="filter" class="text-white mb-0 pl-1">Institute</h5>
<select id="filter" class="form-control" name="institute">
<option selected></option>
{% for institute in institutes %}
<option>{{ institute }}</option>
{% endfor %}
</select>
</div>
<div class="mt-2">
<h5 for="filter" class="text-white mb-0 pl-1">Areas of Expertise</h5>
<select id="filter" class="form-control" name="experties">
<option selected></option>
{% for filter in filters %}
<option>{{ filter.field }}</option>
{% endfor %}
</select>
</div>
<button class="btn btn-primary float-right my-3">Search</button>
</form>
</div>
</div>
</div>
</div>

View File

@ -4,7 +4,7 @@ from .models import AreaOfExpertise, Expert
def browser(request):
filters = AreaOfExpertise.objects.all().order_by('field')
aoe = AreaOfExpertise.objects.all().order_by('field')
experts = Expert.objects.all()
@ -12,16 +12,20 @@ def browser(request):
for expert in experts:
institutes.add(expert.institute) if expert.institute is not None else None
if request.GET.get('name'):
name = request.GET.get('name')
institute = request.GET.get('institute')
expertise = request.GET.get('expertise')
if name:
experts = experts.filter(name__contains=request.GET.get('name'))
if request.GET.get('institute'):
if institute:
experts = experts.filter(institute=request.GET.get('institute'))
if request.GET.get('experties'):
experts = experts.filter(expertise=AreaOfExpertise.objects.filter(field=request.GET.get('experties'))).distinct()
if expertise:
experts = experts.filter(expertise=AreaOfExpertise.objects.filter(field=expertise)).distinct()
return render(request, 'expertBrowser.html', {'experts': experts, 'institutes': institutes, 'filters': filters})
return render(request, 'expertBrowser.html', {'experts': experts, 'institutes': institutes, 'aoe': aoe, 'name': name, 'institute': institute, 'expertise': expertise})
def viewer(request, id):