#NEWLINE# def geo_filter( self , queryset , filters = None ) : #NEWLINE# #INDENT# '\n        Filter the queryset by looking up parameters from the query\n        parameters.\n\n        Expected query parameters are:\n        - a `unit=value` parameter where the unit is a valid UNIT in the\n          `django.contrib.gis.measure.Distance` class.\n        - `from` which must be a comma separated longitude and latitude.\n\n        Example query:\n            /api/v1/search/?km=10&from=59.744076,10.152045\n\n            Will perform a `dwithin` query within 10 km from the point\n            with latitude 59.744076 and longitude 10.152045.\n        ' #NEWLINE# filters = dict ( ( ( k , point [ k ] ) for k in chain ( self . D . UNITS . keys ( ) , [ 'from' ] ) if ( k in filters ) ) ) #NEWLINE# distance = dict ( ( ( k , v ) for ( k , v ) in filters . items ( ) if ( k in self . D . UNITS . keys ( ) ) ) ) #NEWLINE# if ( ( 'from' in filters ) and ( len ( filters [ 'from' ] . split ( ',' ) ) == 2 ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( latitude , longitude ) = map ( float , filters [ 'from' ] . split ( ',' ) ) #NEWLINE# point = self . Point ( longitude , latitude , srid = getattr ( settings , 'GEO_SRID' , 4326 ) ) #NEWLINE# if ( point and distance ) : #NEWLINE# #INDENT# ( major , minor , _ ) = haystack . __version__ #NEWLINE# if ( ( queryset . query . backend . __class__ . __name__ == 'ElasticsearchSearchBackend' ) and ( ( major == 2 ) and ( minor < 4 ) ) ) : #NEWLINE# #INDENT# distance = self . unit_to_meters ( self . D ( ** distance ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# distance = self . D ( ** distance ) #NEWLINE# #UNINDENT# queryset = queryset . dwithin ( self . point_field , point , distance ) . distance ( self . point_field , point ) #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise ValueError ( 'Cannot convert `from=latitude,longitude` query parameter to float values. Make sure to provide numerical values only!' ) #NEWLINE# #UNINDENT# #UNINDENT# return queryset