diff --git a/django/contrib/gis/db/backends/base.py b/django/contrib/gis/db/backends/base.py index ff7c30f4d09..570d0a5baeb 100644 --- a/django/contrib/gis/db/backends/base.py +++ b/django/contrib/gis/db/backends/base.py @@ -16,6 +16,9 @@ class BaseSpatialFeatures(object): # Does the database contain a SpatialRefSys model to store SRID information? has_spatialrefsys_table = True + # Does the backend support the django.contrib.gis.utils.add_srs_entry() utility? + supports_add_srs_entry = True + # Reference implementation of 3D functions is: # http://postgis.net/docs/PostGIS_Special_Functions_Index.html#PostGIS_3D_Functions supports_3d_functions = False diff --git a/django/contrib/gis/db/backends/mysql/base.py b/django/contrib/gis/db/backends/mysql/base.py index 769d2fa6098..25ca0da2046 100644 --- a/django/contrib/gis/db/backends/mysql/base.py +++ b/django/contrib/gis/db/backends/mysql/base.py @@ -10,6 +10,7 @@ from django.contrib.gis.db.backends.mysql.operations import MySQLOperations class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures): has_spatialrefsys_table = False + supports_add_srs_entry = False supports_distances_lookups = False supports_transform = False supports_real_shape_operations = False diff --git a/django/contrib/gis/db/backends/oracle/base.py b/django/contrib/gis/db/backends/oracle/base.py index 70b1c16aba6..eaa1ebebe7b 100644 --- a/django/contrib/gis/db/backends/oracle/base.py +++ b/django/contrib/gis/db/backends/oracle/base.py @@ -9,7 +9,7 @@ from django.contrib.gis.db.backends.oracle.operations import OracleOperations class DatabaseFeatures(BaseSpatialFeatures, OracleDatabaseFeatures): - pass + supports_add_srs_entry = False class DatabaseWrapper(OracleDatabaseWrapper): diff --git a/django/contrib/gis/tests/test_spatialrefsys.py b/django/contrib/gis/tests/test_spatialrefsys.py index e22ff3ada38..7f43124e5d0 100644 --- a/django/contrib/gis/tests/test_spatialrefsys.py +++ b/django/contrib/gis/tests/test_spatialrefsys.py @@ -105,6 +105,7 @@ class SpatialRefSysTest(unittest.TestCase): for i in range(3): self.assertAlmostEqual(ellps1[i], ellps2[i], prec[i]) + @skipUnlessDBFeature('supports_add_srs_entry') def test_add_entry(self): """ Test adding a new entry in the SpatialRefSys model using the diff --git a/django/contrib/gis/utils/srs.py b/django/contrib/gis/utils/srs.py index bb238660101..e5aa5a70395 100644 --- a/django/contrib/gis/utils/srs.py +++ b/django/contrib/gis/utils/srs.py @@ -39,9 +39,8 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, if not hasattr(connection.ops, 'spatial_version'): raise Exception('The `add_srs_entry` utility only works ' 'with spatial backends.') - if connection.ops.oracle or connection.ops.mysql: - raise Exception('This utility does not support the ' - 'Oracle or MySQL spatial backends.') + if not connection.features.supports_add_srs_entry: + raise Exception('This utility does not support your database backend.') SpatialRefSys = connection.ops.spatial_ref_sys() # If argument is not a `SpatialReference` instance, use it as parameter