def search(request, src=None): ''' @summary: For ajax search of Person select field @src: Source of access. It is being used to manipulate the context/templates. eg. src='public_url' means this view is being accessed using some public url. ''' # Search query if ('q' in request.GET) and request.GET['q'].strip(): query_string = request.GET['q'] entry_query = get_query(query_string, ['name', 'additional_name',]) obj_list = Person.objects.filter(entry_query).order_by('name')[:5] else: obj_list = [] result = [] for obj in obj_list: data = {} data['id'] = obj.id data['name'] = obj.name data['name_en'] = obj.additional_name#TODO change name_en to additional_name, elswhere in javascripts data['birth'] = obj.year_birth if obj.year_birth else '' data['death'] = obj.year_death if obj.year_death else '' data['url'] = obj.get_absolute_url() result.append(data) r = json.dumps(result) return HttpResponse(r, content_type="application/json")
def organization(request): ''' For ajax search of `Organization` select field ''' # Search query if ('q' in request.GET) and request.GET['q'].strip(): query_string = request.GET['q'] entry_query = get_query(query_string, [ 'name', ]) obj_list = Organization.objects.filter(entry_query).order_by( 'name')[:5] else: obj_list = [] result = [] for obj in obj_list: data = {} data['id'] = obj.id data['name'] = obj.name data['url'] = obj.get_absolute_url() result.append(data) r = json.dumps(result) return HttpResponse(r, content_type="application/json")
def person(request): ''' For ajax search of `Person` select field ''' # Search query if ('q' in request.GET) and request.GET['q'].strip(): query_string = request.GET['q'] entry_query = get_query(query_string, ['name', 'additional_name',]) obj_list = Person.objects.filter(entry_query).order_by('name')[:5] else: obj_list = [] result = [] for obj in obj_list: data = {} data['id'] = obj.id data['name'] = obj.name data['additional_name'] = obj.additional_name data['birth'] = obj.year_birth if obj.year_birth else '' data['death'] = obj.year_death if obj.year_death else '' data['url'] = obj.get_absolute_url() result.append(data) r = json.dumps(result) return HttpResponse(r, content_type="application/json")