From 25f4e71ed30befbd6af02a7d35807d0d3170e57d Mon Sep 17 00:00:00 2001
From: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Sun, 8 Jun 2014 09:54:35 +0200
Subject: [PATCH] [1.7.x] Gave unique names to SpatialRefSysModels.

Prevented clashes in the app registry.

Fixed #22790. Thanks timo for the report.

Backport of 6e5651e from master
---
 django/contrib/gis/db/backends/base.py                  | 2 +-
 django/contrib/gis/db/backends/oracle/models.py         | 6 ++++--
 django/contrib/gis/db/backends/oracle/operations.py     | 8 ++++----
 django/contrib/gis/db/backends/postgis/models.py        | 4 ++--
 django/contrib/gis/db/backends/postgis/operations.py    | 6 +++---
 django/contrib/gis/db/backends/spatialite/models.py     | 6 ++++--
 django/contrib/gis/db/backends/spatialite/operations.py | 8 ++++----
 django/contrib/gis/tests/utils.py                       | 6 +++---
 8 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/django/contrib/gis/db/backends/base.py b/django/contrib/gis/db/backends/base.py
index 73300ba997..9a92ea4da5 100644
--- a/django/contrib/gis/db/backends/base.py
+++ b/django/contrib/gis/db/backends/base.py
@@ -1,6 +1,6 @@
 """
 Base/mixin classes for the spatial backend database operations and the
-`SpatialRefSys` model the backend.
+`<Backend>SpatialRefSys` model.
 """
 import re
 
diff --git a/django/contrib/gis/db/backends/oracle/models.py b/django/contrib/gis/db/backends/oracle/models.py
index 5fe5efc612..3b7bbf665b 100644
--- a/django/contrib/gis/db/backends/oracle/models.py
+++ b/django/contrib/gis/db/backends/oracle/models.py
@@ -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
 
diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py
index c409dcbb68..3af78929f8 100644
--- a/django/contrib/gis/db/backends/oracle/operations.py
+++ b/django/contrib/gis/db/backends/oracle/operations.py
@@ -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
diff --git a/django/contrib/gis/db/backends/postgis/models.py b/django/contrib/gis/db/backends/postgis/models.py
index 02d92c2887..2dae1529ec 100644
--- a/django/contrib/gis/db/backends/postgis/models.py
+++ b/django/contrib/gis/db/backends/postgis/models.py
@@ -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.
@@ -46,7 +46,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.
diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py
index d85cc06bd7..de4c6c81d2 100644
--- a/django/contrib/gis/db/backends/postgis/operations.py
+++ b/django/contrib/gis/db/backends/postgis/operations.py
@@ -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
diff --git a/django/contrib/gis/db/backends/spatialite/models.py b/django/contrib/gis/db/backends/spatialite/models.py
index 22721ee1c5..9e16f0ef1d 100644
--- a/django/contrib/gis/db/backends/spatialite/models.py
+++ b/django/contrib/gis/db/backends/spatialite/models.py
@@ -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
diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py
index d3e260aaf9..f07d654531 100644
--- a/django/contrib/gis/db/backends/spatialite/operations.py
+++ b/django/contrib/gis/db/backends/spatialite/operations.py
@@ -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
diff --git a/django/contrib/gis/tests/utils.py b/django/contrib/gis/tests/utils.py
index a53b9a3564..aad978039f 100644
--- a/django/contrib/gis/tests/utils.py
+++ b/django/contrib/gis/tests/utils.py
@@ -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