Exemplo n.º 1
0
def get_by_coords(request):
    result = []
    if request.method == 'GET':
        lat = float(request.GET.get('lat', 0.0))
        lon = float(request.GET.get('lon', 0.0))
        if lat != 0.0 and lon != 0.0:
            city_id = geolocal.get_border_codes_by_coords(lat, lon)
            result = map(lambda code: borderdata.get_data_by_port(code),
                geolocal.get_border_codes(city_id))
    return HttpResponse(json_dumps({
            'city_name': borderdata.get_city_name(city_id),
            'borders': result
        }), mimetype='application/json')
Exemplo n.º 2
0
def home(request, city=None):
    #search permalinks in the url
    if city is not None:
        city_id = borderdata.get_city_by_alias(city)
    else:
        city_id = geolocal.get_city_id(request)
    city_info = borderdata.get_city_name(city_id)
    cities = map(
        lambda city: {
            'state': city.state,
            'city': city.name,
            'alias': city.link
        }, MexCity.objects.all()
    )
    return render_to_response('home.html', {
        'city': city_info,
        'city_id': city_id,
        'cities': cities
    }, context_instance=RequestContext(request))