Gave unique names to SpatialRefSysModels.

Prevented clashes in the app registry.

Fixed #22790. Thanks timo for the report.
This commit is contained in:
Aymeric Augustin 2014-06-08 09:54:35 +02:00
parent d8f6b55aa8
commit 6e5651e514
8 changed files with 25 additions and 21 deletions

View File

@ -1,6 +1,6 @@
"""
Base/mixin classes for the spatial backend database operations and the
`SpatialRefSys` model the backend.
`<Backend>SpatialRefSys` model.
"""
import re

View File

@ -13,7 +13,7 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class GeometryColumns(models.Model):
class OracleGeometryColumns(models.Model):
"Maps to the Oracle USER_SDO_GEOM_METADATA table."
table_name = models.CharField(max_length=32)
column_name = models.CharField(max_length=1024)
@ -21,6 +21,7 @@ class GeometryColumns(models.Model):
# TODO: Add support for `diminfo` column (type MDSYS.SDO_DIM_ARRAY).
class Meta:
app_label = 'gis'
db_table = 'USER_SDO_GEOM_METADATA'
managed = False
@ -44,7 +45,7 @@ class GeometryColumns(models.Model):
return '%s - %s (SRID: %s)' % (self.table_name, self.column_name, self.srid)
class SpatialRefSys(models.Model, SpatialRefSysMixin):
class OracleSpatialRefSys(models.Model, SpatialRefSysMixin):
"Maps to the Oracle MDSYS.CS_SRS table."
cs_name = models.CharField(max_length=68)
srid = models.IntegerField(primary_key=True)
@ -57,6 +58,7 @@ class SpatialRefSys(models.Model, SpatialRefSysMixin):
objects = models.GeoManager()
class Meta:
app_label = 'gis'
db_table = 'CS_SRS'
managed = False

View File

@ -289,12 +289,12 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
# Routines for getting the OGC-compliant models.
def geometry_columns(self):
from django.contrib.gis.db.backends.oracle.models import GeometryColumns
return GeometryColumns
from django.contrib.gis.db.backends.oracle.models import OracleGeometryColumns
return OracleGeometryColumns
def spatial_ref_sys(self):
from django.contrib.gis.db.backends.oracle.models import SpatialRefSys
return SpatialRefSys
from django.contrib.gis.db.backends.oracle.models import OracleSpatialRefSys
return OracleSpatialRefSys
def modify_insert_params(self, placeholders, params):
"""Drop out insert parameters for NULL placeholder. Needed for Oracle Spatial

View File

@ -7,7 +7,7 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class GeometryColumns(models.Model):
class PostGISGeometryColumns(models.Model):
"""
The 'geometry_columns' table from the PostGIS. See the PostGIS
documentation at Ch. 4.2.2.
@ -47,7 +47,7 @@ class GeometryColumns(models.Model):
self.coord_dimension, self.type, self.srid)
class SpatialRefSys(models.Model, SpatialRefSysMixin):
class PostGISSpatialRefSys(models.Model, SpatialRefSysMixin):
"""
The 'spatial_ref_sys' table from PostGIS. See the PostGIS
documentaiton at Ch. 4.2.1.

View File

@ -13,7 +13,7 @@ from django.db.utils import ProgrammingError
from django.utils import six
from django.utils.functional import cached_property
from .models import GeometryColumns, SpatialRefSys
from .models import PostGISGeometryColumns, PostGISSpatialRefSys
#### Classes used in constructing PostGIS spatial SQL ####
@ -571,7 +571,7 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
# Routines for getting the OGC-compliant models.
def geometry_columns(self):
return GeometryColumns
return PostGISGeometryColumns
def spatial_ref_sys(self):
return SpatialRefSys
return PostGISSpatialRefSys

View File

@ -7,7 +7,7 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class GeometryColumns(models.Model):
class SpatialiteGeometryColumns(models.Model):
"""
The 'geometry_columns' table from SpatiaLite.
"""
@ -19,6 +19,7 @@ class GeometryColumns(models.Model):
spatial_index_enabled = models.IntegerField()
class Meta:
app_label = 'gis'
db_table = 'geometry_columns'
managed = False
@ -44,7 +45,7 @@ class GeometryColumns(models.Model):
self.coord_dimension, self.type, self.srid)
class SpatialRefSys(models.Model, SpatialRefSysMixin):
class SpatialiteSpatialRefSys(models.Model, SpatialRefSysMixin):
"""
The 'spatial_ref_sys' table from SpatiaLite.
"""
@ -64,5 +65,6 @@ class SpatialRefSys(models.Model, SpatialRefSysMixin):
return SpatialReference(self.proj4text).wkt
class Meta:
app_label = 'gis'
db_table = 'spatial_ref_sys'
managed = False

View File

@ -372,9 +372,9 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
# Routines for getting the OGC-compliant models.
def geometry_columns(self):
from django.contrib.gis.db.backends.spatialite.models import GeometryColumns
return GeometryColumns
from django.contrib.gis.db.backends.spatialite.models import SpatialiteGeometryColumns
return SpatialiteGeometryColumns
def spatial_ref_sys(self):
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
return SpatialRefSys
from django.contrib.gis.db.backends.spatialite.models import SpatialiteSpatialRefSys
return SpatialiteSpatialRefSys

View File

@ -41,11 +41,11 @@ spatialite = _default_db == 'spatialite'
HAS_SPATIALREFSYS = True
if oracle and 'gis' in settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE']:
from django.contrib.gis.db.backends.oracle.models import SpatialRefSys
from django.contrib.gis.db.backends.oracle.models import OracleSpatialRefSys as SpatialRefSys
elif postgis:
from django.contrib.gis.db.backends.postgis.models import SpatialRefSys
from django.contrib.gis.db.backends.postgis.models import PostGISSpatialRefSys as SpatialRefSys
elif spatialite:
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
from django.contrib.gis.db.backends.spatialite.models import SpatialiteSpatialRefSys as SpatialRefSys
else:
HAS_SPATIALREFSYS = False
SpatialRefSys = None