From 152b9ba7173e74fae11c770be40656cc70188514 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Tue, 9 Sep 2008 19:19:51 +0000 Subject: [PATCH] Fixed #8881 by specifying the geometry column name; added the `geom_col_name` classmethod to `GeometryColumns` for Oracle and PostGIS. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8994 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../contrib/gis/db/backend/oracle/models.py | 12 ++++++++ .../contrib/gis/db/backend/postgis/models.py | 13 +++++++- django/contrib/gis/utils/layermapping.py | 30 +++++++++++-------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/django/contrib/gis/db/backend/oracle/models.py b/django/contrib/gis/db/backend/oracle/models.py index c740b48efe..d8d00d402d 100644 --- a/django/contrib/gis/db/backend/oracle/models.py +++ b/django/contrib/gis/db/backend/oracle/models.py @@ -21,8 +21,20 @@ class GeometryColumns(models.Model): @classmethod def table_name_col(cls): + """ + Returns the name of the metadata column used to store the + the feature table name. + """ return 'table_name' + @classmethod + def geom_col_name(cls): + """ + Returns the name of the metadata column used to store the + the feature geometry column. + """ + return 'column_name' + def __unicode__(self): return '%s - %s (SRID: %s)' % (self.table_name, self.column_name, self.srid) diff --git a/django/contrib/gis/db/backend/postgis/models.py b/django/contrib/gis/db/backend/postgis/models.py index e032da4d89..4a814dc1fe 100644 --- a/django/contrib/gis/db/backend/postgis/models.py +++ b/django/contrib/gis/db/backend/postgis/models.py @@ -27,9 +27,20 @@ class GeometryColumns(models.Model): @classmethod def table_name_col(cls): - "Class method for returning the table name column for this model." + """ + Returns the name of the metadata column used to store the + the feature table name. + """ return 'f_table_name' + @classmethod + def geom_col_name(cls): + """ + Returns the name of the metadata column used to store the + the feature geometry column. + """ + return 'f_geometry_column' + def __unicode__(self): return "%s.%s - %dD %s field (SRID: %d)" % \ (self.f_table_name, self.f_geometry_column, diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py index ad0cd5b4d6..c97c202dcb 100644 --- a/django/contrib/gis/utils/layermapping.py +++ b/django/contrib/gis/utils/layermapping.py @@ -179,13 +179,16 @@ class LayerMapping(object): self.ds = data self.layer = self.ds[layer] - # Setting the mapping + # Setting the mapping & model attributes. self.mapping = mapping - - # Setting the model, and getting the geometry column associated - # with the model (an exception will be raised if there is no - # geometry column). self.model = model + + # Checking the layer -- intitialization of the object will fail if + # things don't check out before hand. + self.check_layer() + + # Getting the geometry column associated with the model (an + # exception will be raised if there is no geometry column). self.geo_col = self.geometry_column() # Checking the source spatial reference system, and getting @@ -197,10 +200,6 @@ class LayerMapping(object): else: self.transform = transform - # Checking the layer -- intitialization of the object will fail if - # things don't check out before hand. - self.check_layer() - # Setting the encoding for OFTString fields, if specified. if encoding: # Making sure the encoding exists, if not a LookupError @@ -246,7 +245,8 @@ class LayerMapping(object): there is no need to increment through each feature in the Layer. """ # The geometry field of the model is set here. - # TODO: Support more than one geometry field / model. + # TODO: Support more than one geometry field / model. However, this + # depends on the GDAL Driver in use. self.geom_field = False self.fields = {} @@ -512,8 +512,14 @@ class LayerMapping(object): # Getting the GeometryColumn object. try: db_table = self.model._meta.db_table - if SpatialBackend.name == 'oracle': db_table = db_table.upper() - gc_kwargs = {GeometryColumns.table_name_col() : db_table} + geo_col = self.geom_field + if SpatialBackend.name == 'oracle': + # Making upper case for Oracle. + db_table = db_table.upper() + geo_col = geo_col.upper() + gc_kwargs = {GeometryColumns.table_name_col() : db_table, + GeometryColumns.geom_col_name() : geo_col, + } return GeometryColumns.objects.get(**gc_kwargs) except Exception, msg: raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)