From 32969c3931dea8488ee4ad2849eab43e31e5542e Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sun, 1 May 2016 20:05:19 -0400 Subject: [PATCH] Refs 2bd1bbc -- Made GeometryField.get_db_prep_lookup() a private (deprecated) method. --- django/contrib/gis/db/models/fields.py | 38 ++++++++------------------ django/contrib/gis/db/models/query.py | 6 ++-- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py index 49d86f7618..4fa9674419 100644 --- a/django/contrib/gis/db/models/fields.py +++ b/django/contrib/gis/db/models/fields.py @@ -295,40 +295,26 @@ class GeometryField(GeoSelectFormatMixin, BaseSpatialField): defaults['widget'] = forms.Textarea 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 necessary for the query. This includes wrapping any geometry parameters with a backend-specific adapter and formatting any distance parameters into the correct units for the coordinate system of the 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: - raise ValueError('%s is not a valid spatial lookup for %s.' % - (lookup_type, self.__class__.__name__)) + params = [connection.ops.Adapter(value)] + return params def get_prep_lookup(self, lookup_type, value): if lookup_type == 'contains': diff --git a/django/contrib/gis/db/models/query.py b/django/contrib/gis/db/models/query.py index 65d7fb4503..d0a80f9e56 100644 --- a/django/contrib/gis/db/models/query.py +++ b/django/contrib/gis/db/models/query.py @@ -453,7 +453,7 @@ class GeoQuerySet(QuerySet): # Using the field's get_placeholder() routine to get any needed # transformation SQL. 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) # Replacing the procedure format with that of any needed @@ -510,7 +510,7 @@ class GeoQuerySet(QuerySet): raise ValueError('Unknown distance function: %s' % func) 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 # parameters that will be passed in to field's function. lookup_params = [geom or 'POINT (0 0)', 0] @@ -526,7 +526,7 @@ class GeoQuerySet(QuerySet): (not geography) and length): lookup_params.append('spheroid') 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 # passed in.