~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/contrib/gis/db/backends/postgis/introspection.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
2
2
from django.contrib.gis.gdal import OGRGeomType
3
3
 
 
4
 
4
5
class GeoIntrospectionError(Exception):
5
6
    pass
6
7
 
 
8
 
7
9
class PostGISIntrospection(DatabaseIntrospection):
8
10
    # Reverse dictionary for PostGIS geometry types not populated until
9
11
    # introspection is actually performed.
32
34
        try:
33
35
            cursor.execute(oid_sql, ('geometry',))
34
36
            GEOM_TYPE = cursor.fetchone()[0]
35
 
            postgis_types = { GEOM_TYPE : 'GeometryField' }
 
37
            postgis_types = {GEOM_TYPE: 'GeometryField'}
36
38
            if self.connection.ops.geography:
37
39
                cursor.execute(oid_sql, ('geography',))
38
40
                GEOG_TYPE = cursor.fetchone()[0]
39
41
                # The value for the geography type is actually a tuple
40
42
                # to pass in the `geography=True` keyword to the field
41
43
                # definition.
42
 
                postgis_types[GEOG_TYPE] = ('GeometryField', {'geography' : True})
 
44
                postgis_types[GEOG_TYPE] = ('GeometryField', {'geography': True})
43
45
        finally:
44
46
            cursor.close()
45
47
 
49
51
        if not self.postgis_types_reverse:
50
52
            # If the PostGIS types reverse dictionary is not populated, do so
51
53
            # now.  In order to prevent unnecessary requests upon connection
52
 
            # intialization, the `data_types_reverse` dictionary is not updated
 
54
            # initialization, the `data_types_reverse` dictionary is not updated
53
55
            # with the PostGIS custom types until introspection is actually
54
56
            # performed -- in other words, when this function is called.
55
57
            self.postgis_types_reverse = self.get_postgis_types()
72
74
                               'WHERE "f_table_name"=%s AND "f_geometry_column"=%s',
73
75
                               (table_name, geo_col))
74
76
                row = cursor.fetchone()
75
 
                if not row: raise GeoIntrospectionError
 
77
                if not row:
 
78
                    raise GeoIntrospectionError
76
79
            except GeoIntrospectionError:
77
80
                if self.connection.ops.geography:
78
81
                    cursor.execute('SELECT "coord_dimension", "srid", "type" '