summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-07-05 15:40:55 +0000
committerJustin Bronn <jbronn@gmail.com>2008-07-05 15:40:55 +0000
commit597b07117af5e2d2aa69ddf254f9082e6fe2d608 (patch)
tree6973fdc23dcebc54c7d99750e41418ddec90b85d
parentbc3d6b49089ef0ea7d174eb383b1019b6a4a061a (diff)
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
-rw-r--r--django/contrib/gis/db/models/sql/where.py41
1 files changed, 12 insertions, 29 deletions
diff --git a/django/contrib/gis/db/models/sql/where.py b/django/contrib/gis/db/models/sql/where.py
index 68f5e247a0..a1a28d9511 100644
--- a/django/contrib/gis/db/models/sql/where.py
+++ b/django/contrib/gis/db/models/sql/where.py
@@ -25,43 +25,26 @@ class GeoWhereNode(WhereNode):
This is overridden from the regular WhereNode to handle the
peculiarties of GeometryFields, because they need a special
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)):
- super(WhereNode, self).add(data, connector)
- return
-
- alias, col, field, lookup_type, value = data
- # Do we have a geographic field?
- 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()
+ return super(WhereNode, self).add(data, connector)
+ alias, col, field, lookup_type, value = data
+ if not hasattr(field, "_geom"):
+ # Not a geographic field, so call `WhereNode.add`.
+ return super(GeoWhereNode, self).add(data, connector)
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:
+ # `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)
+
# The annotation will be a `GeoAnnotation` object that
# will contain the necessary geometry field metadata for
# the `get_geo_where_clause` to construct the appropriate
# spatial SQL when `make_atom` is called.
annotation = GeoAnnotation(field, value, where)
- elif isinstance(value, datetime.datetime):
- annotation = datetime.datetime
- else:
- annotation = bool(value)
-
- super(WhereNode, self).add((alias, col, db_type, lookup_type,
- annotation, params), connector)
+ return super(WhereNode, self).add((alias, col, field.db_type(), lookup_type,
+ annotation, params), connector)
def make_atom(self, child, qn):
table_alias, name, db_type, lookup_type, value_annot, params = child