- Timestamp:
- 05/01/08 13:17:50 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/db/backend/__init__.py
r7482 r7512 3 3 4 4 Specifically, this module will import the correct routines and modules 5 needed for GeoDjango .5 needed for GeoDjango to interface with the spatial database. 6 6 7 Some of the more important classes and routines from the spatial backend 8 include: 9 7 10 (1) `GeoBackEndField`, a base class needed for GeometryField. 8 (2) `GeoWhereNode`, a subclass of `WhereNode` used to contruct spatial SQL. 9 (3) `SpatialBackend`, a container object for information specific to the 11 (2) `get_geo_where_clause`, a routine used by `GeoWhereNode`. 12 (3) `GIS_TERMS`, a listing of all valid GeoDjango lookup types. 13 (4) `SpatialBackend`, a container object for information specific to the 10 14 spatial backend. 11 15 """ 12 16 from django.conf import settings 13 17 from django.db.models.sql.query import QUERY_TERMS 14 from django.db.models.sql.where import WhereNode15 18 from django.contrib.gis.db.backend.util import gqn 16 19 … … 62 65 raise NotImplementedError('No Geographic Backend exists for %s' % settings.DATABASE_ENGINE) 63 66 64 class GeoWhereNode(WhereNode):65 """66 The GeoWhereNode calls the `get_geo_where_clause` from the appropriate67 spatial backend in order to construct correct spatial SQL.68 """69 def make_atom(self, child, qn):70 table_alias, name, field, lookup_type, value = child71 if hasattr(field, '_geom'):72 if lookup_type in GIS_TERMS:73 # Getting the geographic where clause; substitution parameters74 # will be populated in the GeoFieldSQL object returned by the75 # GeometryField.76 gwc = get_geo_where_clause(lookup_type, table_alias, field, value)77 where, params = field.get_db_prep_lookup(lookup_type, value)78 return gwc % tuple(where), params79 else:80 raise TypeError('Invalid lookup type: %r' % lookup_type)81 else:82 # If not a GeometryField, call the `make_atom` from the83 # base class.84 return super(GeoWhereNode, self).make_atom(child, qn)85 86 67 class SpatialBackend(object): 87 68 "A container for properties of the SpatialBackend." … … 107 88 limited_where = LIMITED_WHERE 108 89 90 # Shortcut booleans. 91 mysql = SPATIAL_BACKEND == 'mysql' 92 oracle = SPATIAL_BACKEND == 'oracle' 93 postgis = SPATIAL_BACKEND == 'postgis' 94 109 95 # Class for the backend field. 110 96 Field = GeoBackendField
