Django

Code

Changeset 7699

Show
Ignore:
Timestamp:
06/19/08 01:00:13 (5 months ago)
Author:
jbronn
Message:

gis: Fixed spatial aggregates when an ordering was specified (thanks ingenieroariel); added bboverlaps to MySQL lookup types for API consistency.

Files:

Legend:

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

    r7104 r7699  
    2020MYSQL_GIS_FUNCTIONS = { 
    2121    'bbcontains' : 'MBRContains', # For consistency w/PostGIS API 
    22     'contained' : 'MBRWithin',    # (ditto) 
     22    'bboverlaps' : 'MBROverlaps', # .. .. 
     23    'contained' : 'MBRWithin',    # .. .. 
    2324    'contains' : 'MBRContains', 
    2425    'disjoint' : 'MBRDisjoint', 
  • django/branches/gis/django/contrib/gis/db/models/query.py

    r7641 r7699  
    602602        ForeignKey relation to the current model. 
    603603        """ 
     604        # If this is an aggregate spatial query, the flag needs to be 
     605        # set on the `GeoQuery` object of this queryset. 
     606        if aggregate: self.query.aggregate = True 
     607 
    604608        # Is this operation going to be on a related geographic field? 
    605609        if not geo_field in self.model._meta.fields: 
     
    608612            self.query.add_select_related([field_name]) 
    609613            self.query.pre_sql_setup() 
    610             # Can't non-aggregate and aggregate selections together. 
    611             if aggregate: self.query.aggregate = True  
    612614            rel_table, rel_col = self.query.related_select_cols[self.query.related_select_fields.index(geo_field)] 
    613615            return self.query._field_column(geo_field, rel_table) 
  • django/branches/gis/django/contrib/gis/db/models/sql/query.py

    r7641 r7699  
    148148        return result, aliases 
    149149 
     150    def get_ordering(self): 
     151        """ 
     152        This routine is overridden to disable ordering for aggregate 
     153        spatial queries. 
     154        """ 
     155        if not self.aggregate: 
     156            return super(GeoQuery, self).get_ordering() 
     157        else: 
     158            return () 
     159 
    150160    def resolve_columns(self, row, fields=()): 
    151161        """ 
  • django/branches/gis/django/contrib/gis/tests/geoapp/tests.py

    r7641 r7699  
    432432        qs = City.objects.filter(point__within=tx) 
    433433        self.assertRaises(TypeError, qs.unionagg, 'name') 
    434         u1 = qs.unionagg(field_name='point') 
    435         u2 = qs.unionagg() 
     434        # Using `field_name` keyword argument in one query and specifying an 
     435        # order in the other (which should not be used because this is 
     436        # an aggregate method on a spatial column) 
     437        u1 = qs.unionagg(field_name='point')  
     438        u2 = qs.order_by('name').unionagg() 
    436439        tol = 0.00001 
    437440        if SpatialBackend.oracle: