oacpl/expert_witnesses/views.py

34 lines
1.0 KiB
Python
Raw Normal View History

2017-09-05 02:24:39 -04:00
from django.shortcuts import render
2017-09-14 13:52:39 -04:00
from .models import AreaOfExpertise, Expert
def browser(request):
2017-10-02 15:41:05 -04:00
aoe = AreaOfExpertise.objects.all().order_by('field')
2017-09-16 18:45:28 -04:00
2017-09-14 13:52:39 -04:00
experts = Expert.objects.all()
2017-09-16 18:45:28 -04:00
institutes = set()
for expert in experts:
institutes.add(expert.institute) if expert.institute is not None else None
2017-10-02 15:41:05 -04:00
name = request.GET.get('name')
institute = request.GET.get('institute')
expertise = request.GET.get('expertise')
if name:
2017-09-16 18:45:28 -04:00
experts = experts.filter(name__contains=request.GET.get('name'))
2017-10-02 15:41:05 -04:00
if institute:
2017-09-16 18:45:28 -04:00
experts = experts.filter(institute=request.GET.get('institute'))
2017-10-02 15:41:05 -04:00
if expertise:
experts = experts.filter(expertise=AreaOfExpertise.objects.filter(field=expertise)).distinct()
2017-09-16 18:45:28 -04:00
2017-10-02 15:41:05 -04:00
return render(request, 'expertBrowser.html', {'experts': experts, 'institutes': institutes, 'aoe': aoe, 'name': name, 'institute': institute, 'expertise': expertise})
2017-09-14 13:52:39 -04:00
def viewer(request, id):
expert = Expert.objects.get(id=id)
return render(request, 'expertViewer.html', {'expert': expert})