Django

Code

Show
Ignore:
Timestamp:
07/05/08 10:40:55 (6 months ago)
Author:
jbronn
Message:

gis: Revised changes to GeoWhereNode to reduce code duplication. Thanks, Malcolm.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/models/sql/where.py

    r7836 r7839  
    2626        peculiarties of GeometryFields, because they need a special  
    2727        annotation object that contains the spatial metadata from the  
    28         field so that the correct spatial SQL is generated
     28        field to generate the spatial SQL
    2929        """ 
    3030        if not isinstance(data, (list, tuple)): 
    31             super(WhereNode, self).add(data, connector) 
    32             return 
     31            return super(WhereNode, self).add(data, connector) 
     32        alias, col, field, lookup_type, value = data      
     33        if not hasattr(field, "_geom"): 
     34            # Not a geographic field, so call `WhereNode.add`. 
     35            return super(GeoWhereNode, self).add(data, connector) 
     36        else: 
     37            # `GeometryField.get_db_prep_lookup` returns a where clause 
     38            # substitution array in addition to the parameters. 
     39            where, params = field.get_db_prep_lookup(lookup_type, value) 
    3340 
    34         alias, col, field, lookup_type, value = data 
    35         # Do we have a geographic field? 
    36         geo_field = hasattr(field, '_geom') 
    37         if field: 
    38             if geo_field: 
    39                 # `GeometryField.get_db_prep_lookup` returns a where clause 
    40                 # substitution array in addition to the parameters. 
    41                 where, params = field.get_db_prep_lookup(lookup_type, value) 
    42             else: 
    43                 params = field.get_db_prep_lookup(lookup_type, value) 
    44             db_type = field.db_type() 
    45         else: 
    46             # This is possible when we add a comparison to NULL sometimes (we 
    47             # don't really need to waste time looking up the associated field 
    48             # object). 
    49             params = Field().get_db_prep_lookup(lookup_type, value) 
    50             db_type = None 
    51    
    52         if geo_field: 
    5341            # The annotation will be a `GeoAnnotation` object that 
    5442            # will contain the necessary geometry field metadata for 
     
    5644            # spatial SQL when `make_atom` is called. 
    5745            annotation = GeoAnnotation(field, value, where) 
    58         elif isinstance(value, datetime.datetime): 
    59             annotation = datetime.datetime 
    60         else: 
    61             annotation = bool(value) 
    62  
    63         super(WhereNode, self).add((alias, col, db_type, lookup_type, 
    64                                     annotation, params), connector) 
     46            return super(WhereNode, self).add((alias, col, field.db_type(), lookup_type, 
     47                                               annotation, params), connector) 
    6548 
    6649    def make_atom(self, child, qn):