Refs 2bd1bbc -- Made GeometryField.get_db_prep_lookup() a private (deprecated) method.

This commit is contained in:
Tim Graham 2016-05-01 20:05:19 -04:00
parent eab5df12b6
commit 32969c3931
2 changed files with 15 additions and 29 deletions

View File

@ -295,40 +295,26 @@ class GeometryField(GeoSelectFormatMixin, BaseSpatialField):
defaults['widget'] = forms.Textarea defaults['widget'] = forms.Textarea
return super(GeometryField, self).formfield(**defaults) return super(GeometryField, self).formfield(**defaults)
def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): def _get_db_prep_lookup(self, lookup_type, value, connection):
""" """
Prepare for the database lookup, and return any spatial parameters Prepare for the database lookup, and return any spatial parameters
necessary for the query. This includes wrapping any geometry necessary for the query. This includes wrapping any geometry
parameters with a backend-specific adapter and formatting any distance parameters with a backend-specific adapter and formatting any distance
parameters into the correct units for the coordinate system of the parameters into the correct units for the coordinate system of the
field. field.
"""
# special case for isnull lookup
if lookup_type == 'isnull':
return []
elif lookup_type in self.class_lookups:
# Populating the parameters list, and wrapping the Geometry
# with the Adapter of the spatial backend.
if isinstance(value, (tuple, list)):
params = [connection.ops.Adapter(value[0])]
if self.class_lookups[lookup_type].distance:
# Getting the distance parameter in the units of the field.
params += self.get_distance(value[1:], lookup_type, connection)
elif lookup_type in connection.ops.truncate_params:
# Lookup is one where SQL parameters aren't needed from the
# given lookup value.
pass
else:
params += value[1:]
elif isinstance(value, Expression):
params = []
else:
params = [connection.ops.Adapter(value)]
return params Only used by the deprecated GeoQuerySet and to be
RemovedInDjango20Warning.
"""
# Populating the parameters list, and wrapping the Geometry
# with the Adapter of the spatial backend.
if isinstance(value, (tuple, list)):
params = [connection.ops.Adapter(value[0])]
# Getting the distance parameter in the units of the field.
params += self.get_distance(value[1:], lookup_type, connection)
else: else:
raise ValueError('%s is not a valid spatial lookup for %s.' % params = [connection.ops.Adapter(value)]
(lookup_type, self.__class__.__name__)) return params
def get_prep_lookup(self, lookup_type, value): def get_prep_lookup(self, lookup_type, value):
if lookup_type == 'contains': if lookup_type == 'contains':

View File

@ -453,7 +453,7 @@ class GeoQuerySet(QuerySet):
# Using the field's get_placeholder() routine to get any needed # Using the field's get_placeholder() routine to get any needed
# transformation SQL. # transformation SQL.
geom = geo_field.get_prep_value(settings['procedure_args'][name]) geom = geo_field.get_prep_value(settings['procedure_args'][name])
params = geo_field.get_db_prep_lookup('contains', geom, connection=connection) params = geo_field._get_db_prep_lookup('contains', geom, connection=connection)
geom_placeholder = geo_field.get_placeholder(geom, None, connection) geom_placeholder = geo_field.get_placeholder(geom, None, connection)
# Replacing the procedure format with that of any needed # Replacing the procedure format with that of any needed
@ -510,7 +510,7 @@ class GeoQuerySet(QuerySet):
raise ValueError('Unknown distance function: %s' % func) raise ValueError('Unknown distance function: %s' % func)
geom_3d = geo_field.dim == 3 geom_3d = geo_field.dim == 3
# The field's get_db_prep_lookup() is used to get any # The field's _get_db_prep_lookup() is used to get any
# extra distance parameters. Here we set up the # extra distance parameters. Here we set up the
# parameters that will be passed in to field's function. # parameters that will be passed in to field's function.
lookup_params = [geom or 'POINT (0 0)', 0] lookup_params = [geom or 'POINT (0 0)', 0]
@ -526,7 +526,7 @@ class GeoQuerySet(QuerySet):
(not geography) and length): (not geography) and length):
lookup_params.append('spheroid') lookup_params.append('spheroid')
lookup_params = geo_field.get_prep_value(lookup_params) lookup_params = geo_field.get_prep_value(lookup_params)
params = geo_field.get_db_prep_lookup('distance_lte', lookup_params, connection=connection) params = geo_field._get_db_prep_lookup('distance_lte', lookup_params, connection=connection)
# The `geom_args` flag is set to true if a geometry parameter was # The `geom_args` flag is set to true if a geometry parameter was
# passed in. # passed in.