Пример #1
0
def site_search(request):
    query = request.GET.get("query")
    state = request.GET.get("state")

    bills = []
    people = []
    if query:
        bills = search_bills(state=state, query=query, sort="-latest_action")

        # pagination
        page_num = int(request.GET.get("page", 1))
        bills_paginator = Paginator(bills, 20)
        try:
            bills = bills_paginator.page(page_num)
        except EmptyPage:
            raise Http404()

        # people search
        people = []
        for p in Person.objects.search(query, state=state):
            pd = person_as_dict(p)
            pd["current_state"] = jid_to_abbr(
                p.current_jurisdiction_id).upper()
            people.append(pd)

    return render(
        request,
        "public/views/search.html",
        {
            "query": query,
            "state": state,
            "bills": bills,
            "people": people
        },
    )
Пример #2
0
def site_search(request):
    query = request.GET.get("query")
    state = request.GET.get("state")

    bills = []
    people = []
    if query:
        bills = search_bills(state=state, query=query)
        bills = bills.order_by(F("latest_action_date").desc(nulls_last=True))

        # pagination
        page_num = int(request.GET.get("page", 1))
        bills_paginator = Paginator(bills, 20)
        try:
            bills = bills_paginator.page(page_num)
        except EmptyPage:
            raise Http404()

        # people search
        people = [
            person_as_dict(p)
            for p in Person.objects.search(query, state=state)
        ]

    return render(
        request,
        "public/views/search.html",
        {
            "query": query,
            "state": state,
            "bills": bills,
            "people": people
        },
    )
Пример #3
0
def legislators(request, state):
    chambers = get_chambers_from_abbr(state)

    legislators = [
        person_as_dict(p)
        for p in Person.objects.current_legislators_with_roles(chambers)
    ]

    chambers = {c.classification: c.name for c in chambers}

    return render(
        request,
        "public/views/legislators.html",
        {
            "state": state,
            "chambers": chambers,
            "legislators": legislators,
            "state_nav": "legislators",
        },
    )