mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
gis: Revised changes to GeoWhereNode
to reduce code duplication. Thanks, Malcolm.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7839 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
bc3d6b4908
commit
597b07117a
@ -25,42 +25,25 @@ class GeoWhereNode(WhereNode):
|
|||||||
This is overridden from the regular WhereNode to handle the
|
This is overridden from the regular WhereNode to handle the
|
||||||
peculiarties of GeometryFields, because they need a special
|
peculiarties of GeometryFields, because they need a special
|
||||||
annotation object that contains the spatial metadata from the
|
annotation object that contains the spatial metadata from the
|
||||||
field so that the correct spatial SQL is generated.
|
field to generate the spatial SQL.
|
||||||
"""
|
"""
|
||||||
if not isinstance(data, (list, tuple)):
|
if not isinstance(data, (list, tuple)):
|
||||||
super(WhereNode, self).add(data, connector)
|
return super(WhereNode, self).add(data, connector)
|
||||||
return
|
|
||||||
|
|
||||||
alias, col, field, lookup_type, value = data
|
alias, col, field, lookup_type, value = data
|
||||||
# Do we have a geographic field?
|
if not hasattr(field, "_geom"):
|
||||||
geo_field = hasattr(field, '_geom')
|
# Not a geographic field, so call `WhereNode.add`.
|
||||||
if field:
|
return super(GeoWhereNode, self).add(data, connector)
|
||||||
if geo_field:
|
else:
|
||||||
# `GeometryField.get_db_prep_lookup` returns a where clause
|
# `GeometryField.get_db_prep_lookup` returns a where clause
|
||||||
# substitution array in addition to the parameters.
|
# substitution array in addition to the parameters.
|
||||||
where, params = field.get_db_prep_lookup(lookup_type, value)
|
where, params = field.get_db_prep_lookup(lookup_type, value)
|
||||||
else:
|
|
||||||
params = field.get_db_prep_lookup(lookup_type, value)
|
|
||||||
db_type = field.db_type()
|
|
||||||
else:
|
|
||||||
# This is possible when we add a comparison to NULL sometimes (we
|
|
||||||
# don't really need to waste time looking up the associated field
|
|
||||||
# object).
|
|
||||||
params = Field().get_db_prep_lookup(lookup_type, value)
|
|
||||||
db_type = None
|
|
||||||
|
|
||||||
if geo_field:
|
|
||||||
# The annotation will be a `GeoAnnotation` object that
|
# The annotation will be a `GeoAnnotation` object that
|
||||||
# will contain the necessary geometry field metadata for
|
# will contain the necessary geometry field metadata for
|
||||||
# the `get_geo_where_clause` to construct the appropriate
|
# the `get_geo_where_clause` to construct the appropriate
|
||||||
# spatial SQL when `make_atom` is called.
|
# spatial SQL when `make_atom` is called.
|
||||||
annotation = GeoAnnotation(field, value, where)
|
annotation = GeoAnnotation(field, value, where)
|
||||||
elif isinstance(value, datetime.datetime):
|
return super(WhereNode, self).add((alias, col, field.db_type(), lookup_type,
|
||||||
annotation = datetime.datetime
|
|
||||||
else:
|
|
||||||
annotation = bool(value)
|
|
||||||
|
|
||||||
super(WhereNode, self).add((alias, col, db_type, lookup_type,
|
|
||||||
annotation, params), connector)
|
annotation, params), connector)
|
||||||
|
|
||||||
def make_atom(self, child, qn):
|
def make_atom(self, child, qn):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user