~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to django/contrib/gis/db/models/aggregates.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090729112628-9qrzwnl9x32jxhbg
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.db.models import Aggregate
 
2
from django.contrib.gis.db.backend import SpatialBackend
 
3
from django.contrib.gis.db.models.sql import GeomField
 
4
 
 
5
class GeoAggregate(Aggregate):
 
6
 
 
7
    def add_to_query(self, query, alias, col, source, is_summary):
 
8
        if hasattr(source, 'geom_type'):
 
9
            # Doing additional setup on the Query object for spatial aggregates.
 
10
            aggregate = getattr(query.aggregates_module, self.name)
 
11
            
 
12
            # Adding a conversion class instance and any selection wrapping
 
13
            # SQL (e.g., needed by Oracle).
 
14
            if aggregate.conversion_class is GeomField:
 
15
                query.extra_select_fields[alias] = GeomField()
 
16
                if SpatialBackend.select:
 
17
                    query.custom_select[alias] = SpatialBackend.select
 
18
     
 
19
        super(GeoAggregate, self).add_to_query(query, alias, col, source, is_summary)
 
20
 
 
21
class Collect(GeoAggregate):
 
22
    name = 'Collect'
 
23
 
 
24
class Extent(GeoAggregate):
 
25
    name = 'Extent'
 
26
 
 
27
class MakeLine(GeoAggregate):
 
28
    name = 'MakeLine'
 
29
 
 
30
class Union(GeoAggregate):
 
31
    name = 'Union'