1
0
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:
Justin Bronn 2008-07-05 15:40:55 +00:00
parent bc3d6b4908
commit 597b07117a

View File

@ -25,43 +25,26 @@ 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
if not hasattr(field, "_geom"):
alias, col, field, lookup_type, value = data # Not a geographic field, so call `WhereNode.add`.
# Do we have a geographic field? return super(GeoWhereNode, self).add(data, connector)
geo_field = hasattr(field, '_geom')
if field:
if geo_field:
# `GeometryField.get_db_prep_lookup` returns a where clause
# substitution array in addition to the parameters.
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: else:
# This is possible when we add a comparison to NULL sometimes (we # `GeometryField.get_db_prep_lookup` returns a where clause
# don't really need to waste time looking up the associated field # substitution array in addition to the parameters.
# object). where, params = field.get_db_prep_lookup(lookup_type, value)
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 annotation, params), connector)
else:
annotation = bool(value)
super(WhereNode, self).add((alias, col, db_type, lookup_type,
annotation, params), connector)
def make_atom(self, child, qn): def make_atom(self, child, qn):
table_alias, name, db_type, lookup_type, value_annot, params = child table_alias, name, db_type, lookup_type, value_annot, params = child