def find_your_legislator(request):
    '''
    Context:
        - request
        - lat
        - long
        - located
        - legislators

    Templates:
        - billy/web/public/find_your_legislator_table.html
    '''

    # check if lat/lon are set
    # if leg_search is set, they most likely don't have ECMAScript enabled.
    # XXX: fallback behavior here for alpha.

    get = request.GET
    context = {}
    template = 'find_your_legislator'

    context['request'] = ""
    if "q" in get:
        context['request'] = get['q']

    if "lat" in get and "lon" in get:
        # We've got a passed lat/lon. Let's build off it.
        lat = get['lat']
        lon = get['lon']

        context['lat'] = lat
        context['lon'] = lon
        context['located'] = True

        qurl = "%slegislators/geo/?long=%s&lat=%s&apikey=%s" % (
            billy_settings.API_BASE_URL,
            lon,
            lat,
            getattr(billy_settings, 'API_KEY', '')
        )
        leg_resp = json.load(urllib2.urlopen(qurl, timeout=0.5))
        # allow limiting lookup to region for region map views
        if 'abbr' in get:
            leg_resp = [leg for leg in leg_resp
                        if leg[billy_settings.LEVEL_FIELD] == get['abbr']]
            context['abbr'] = get['abbr']

        # Also, allow filtering by chamber
        if 'chamber' in get:
            leg_resp = [leg for leg in leg_resp
                        if leg['chamber'] == get['chamber']]
            context['chamber'] = get['chamber']

        if "boundary" in get:
            return HttpResponse(json.dumps([]))

        context['legislators'] = map(Legislator, leg_resp)
        template = 'find_your_legislator_table'

    return render(request, templatename(template), context)
def find_your_legislator ( request ) : get = request . GET context = { } template = 'find_your_legislator' context [ 'request' ] = "" if "q" in get : context [ 'request' ] = get [ 'q' ] if "lat" in get and "lon" in get : lat = get [ 'lat' ] lon = get [ 'lon' ] context [ 'lat' ] = lat context [ 'lon' ] = lon context [ 'located' ] = True qurl = "%slegislators/geo/?long=%s&lat=%s&apikey=%s" % ( billy_settings . API_BASE_URL , lon , lat , getattr ( billy_settings , 'API_KEY' , '' ) ) leg_resp = json . load ( urllib2 . urlopen ( qurl , timeout = 0.5 ) ) if 'abbr' in get : leg_resp = [ leg for leg in leg_resp if leg [ billy_settings . LEVEL_FIELD ] == get [ 'abbr' ] ] context [ 'abbr' ] = get [ 'abbr' ] if 'chamber' in get : leg_resp = [ leg for leg in leg_resp if leg [ 'chamber' ] == get [ 'chamber' ] ] context [ 'chamber' ] = get [ 'chamber' ] if "boundary" in get : return HttpResponse ( json . dumps ( [ ] ) ) context [ 'legislators' ] = map ( Legislator , leg_resp ) template = 'find_your_legislator_table' return render ( request , templatename ( template ) , context )
Context:
        - request
        - lat
        - long
        - located
        - legislators

    Templates:
        - billy/web/public/find_your_legislator_table.html