Django

Code

Show
Ignore:
Timestamp:
05/01/08 13:17:50 (8 months ago)
Author:
jbronn
Message:

gis: Fixed #7126 (with tests); moved GeoQuery and GeoWhereNode into sql submodule; the GeoQuerySet.transform may now be used on geometry fields related via foreign key.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/backend/__init__.py

    r7482 r7512  
    33 
    44 Specifically, this module will import the correct routines and modules 
    5  needed for GeoDjango
     5 needed for GeoDjango to interface with the spatial database
    66  
     7 Some of the more important classes and routines from the spatial backend 
     8 include: 
     9 
    710 (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 
    1014     spatial backend. 
    1115""" 
    1216from django.conf import settings 
    1317from django.db.models.sql.query import QUERY_TERMS 
    14 from django.db.models.sql.where import WhereNode 
    1518from django.contrib.gis.db.backend.util import gqn 
    1619 
     
    6265    raise NotImplementedError('No Geographic Backend exists for %s' % settings.DATABASE_ENGINE) 
    6366 
    64 class GeoWhereNode(WhereNode): 
    65     """ 
    66     The GeoWhereNode calls the `get_geo_where_clause` from the appropriate 
    67     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 = child 
    71         if hasattr(field, '_geom'): 
    72             if lookup_type in GIS_TERMS: 
    73                 # Getting the geographic where clause; substitution parameters 
    74                 # will be populated in the GeoFieldSQL object returned by the 
    75                 # 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), params 
    79             else: 
    80                 raise TypeError('Invalid lookup type: %r' % lookup_type) 
    81         else: 
    82             # If not a GeometryField, call the `make_atom` from the  
    83             # base class. 
    84             return super(GeoWhereNode, self).make_atom(child, qn) 
    85  
    8667class SpatialBackend(object): 
    8768    "A container for properties of the SpatialBackend." 
     
    10788    limited_where = LIMITED_WHERE 
    10889 
     90    # Shortcut booleans. 
     91    mysql = SPATIAL_BACKEND == 'mysql' 
     92    oracle = SPATIAL_BACKEND == 'oracle' 
     93    postgis = SPATIAL_BACKEND == 'postgis' 
     94 
    10995    # Class for the backend field. 
    11096    Field = GeoBackendField