示例#1
0
文件: views.py 项目: jhgouveia/sigi
def map_search(request):
    response = {'result': 'NOT_FOUND'}
    if 'q' in request.GET:
        q = request.GET.get('q')
        if len(q.split(',')) > 1:
            municipio, uf = [s.strip() for s in q.split(',')]
            casas = CasaLegislativa.objects.filter(search_text__icontains=to_ascii(municipio), municipio__uf__sigla__iexact=uf)
        else:
            casas = CasaLegislativa.objects.filter(search_text__icontains=to_ascii(q))
        if casas.count() > 0:
            response = {'result': 'FOUND', 'ids': [c.pk for c in casas]}

    return HttpResponse(simplejson.dumps(response), content_type='application/json')
示例#2
0
def map_search(request):
    response = {'result': 'NOT_FOUND'}
    if 'q' in request.GET:
        q = request.GET.get('q')
        if len(q.split(',')) > 1:
            municipio, uf = [s.strip() for s in q.split(',')]
            casas = CasaLegislativa.objects.filter(
                search_text__icontains=to_ascii(municipio),
                municipio__uf__sigla__iexact=uf)
        else:
            casas = CasaLegislativa.objects.filter(
                search_text__icontains=to_ascii(q))
        if casas.count() > 0:
            response = {'result': 'FOUND', 'ids': [c.pk for c in casas]}

    return HttpResponse(simplejson.dumps(response),
                        content_type='application/json')
示例#3
0
def busca_nominal(request, origin="tudo"):
    term = request.GET.get('term', None)
    if term is None:
        return JsonResponse([{'label': _(u'Erro na pesquisa por termo'), 'value': 'type=error'}], safe=False)

    data = []
    
    if origin == "casa" or origin == "tudo":     
        casas = CasaLegislativa.objects.filter(search_text__icontains=to_ascii(term)).select_related('municipio', 'municipio__uf')[:10]
        data += [{'value': c.pk, 'label': "%s, %s" % (c.nome, c.municipio.uf.sigla,), 'origin': 'casa'} for c in casas]
        
    if origin == "servidor" or origin == "tudo": 
        servidores = Servidor.objects.filter(nome_completo__icontains=term)[:10]
        data += [{'value': s.pk, 'label': s.nome_completo, 'origin': 'servidor'} for s in servidores]
        
    if origin == "servico" or origin == "tudo":
        setores = Servico.objects.filter(nome__icontains=term) | Servico.objects.filter(sigla__icontains=term)
        setores = setores[:10]
        data += [{'value': s.pk, 'label': '%s - %s' % (s.sigla, s.nome), 'origin': 'servico'} for s in setores]
        
    data = sorted(data, key=lambda d: d['label'])
     
    return JsonResponse(data, safe=False)