Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16537 -- Fixed multi-db issues with GeoDjango utilities. Thank…

…s, Shane Shifflett for the bug report and aaugustin for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16779 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 36120f41a900cae27377d247ec482bc427811f51 1 parent 67dde2f
Justin Bronn authored September 10, 2011
7  django/contrib/gis/utils/layermapping.py
@@ -132,9 +132,6 @@ def __init__(self, model, data, mapping, layer=0,
132 132
         else:
133 133
             raise LayerMapError('Unrecognized transaction mode: %s' % transaction_mode)
134 134
 
135  
-        if using is None:
136  
-            pass
137  
-
138 135
     #### Checking routines used during initialization ####
139 136
     def check_fid_range(self, fid_range):
140 137
         "This checks the `fid_range` keyword."
@@ -393,7 +390,7 @@ def verify_fk(self, feat, rel_model, rel_mapping):
393 390
 
394 391
         # Attempting to retrieve and return the related model.
395 392
         try:
396  
-            return rel_model.objects.get(**fk_kwargs)
  393
+            return rel_model.objects.using(self.using).get(**fk_kwargs)
397 394
         except ObjectDoesNotExist:
398 395
             raise MissingForeignKey('No ForeignKey %s model found with keyword arguments: %s' % (rel_model.__name__, fk_kwargs))
399 396
 
@@ -429,7 +426,7 @@ def coord_transform(self):
429 426
         SpatialRefSys = self.spatial_backend.spatial_ref_sys()
430 427
         try:
431 428
             # Getting the target spatial reference system
432  
-            target_srs = SpatialRefSys.objects.get(srid=self.geo_field.srid).srs
  429
+            target_srs = SpatialRefSys.objects.using(self.using).get(srid=self.geo_field.srid).srs
433 430
 
434 431
             # Creating the CoordTransform object
435 432
             return CoordTransform(self.source_srs, target_srs)
11  django/contrib/gis/utils/srs.py
... ...
@@ -1,8 +1,7 @@
1 1
 from django.contrib.gis.gdal import SpatialReference
2  
-from django.db import connections, DEFAULT_DB_ALIAS
3 2
 
4 3
 def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
5  
-                  database=DEFAULT_DB_ALIAS):
  4
+                  database=None):
6 5
     """
7 6
     This function takes a GDAL SpatialReference system and adds its information
8 7
     to the `spatial_ref_sys` table of the spatial backend.  Doing this enables
@@ -33,7 +32,11 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
33 32
       of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, it's value
34 33
       is 'default').
35 34
     """
  35
+    from django.db import connections, DEFAULT_DB_ALIAS
  36
+    if not database:
  37
+        database = DEFAULT_DB_ALIAS
36 38
     connection = connections[database]
  39
+
37 40
     if not hasattr(connection.ops, 'spatial_version'):
38 41
         raise Exception('The `add_srs_entry` utility only works '
39 42
                         'with spatial backends.')
@@ -69,9 +72,9 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
69 72
     try:
70 73
         # Try getting via SRID only, because using all kwargs may
71 74
         # differ from exact wkt/proj in database.
72  
-        sr = SpatialRefSys.objects.get(srid=srs.srid)
  75
+        sr = SpatialRefSys.objects.using(database).get(srid=srs.srid)
73 76
     except SpatialRefSys.DoesNotExist:
74  
-        sr = SpatialRefSys.objects.create(**kwargs)
  77
+        sr = SpatialRefSys.objects.using(database).create(**kwargs)
75 78
 
76 79
 # Alias is for backwards-compatibility purposes.
77 80
 add_postgis_srs = add_srs_entry

0 notes on commit 36120f4

Please sign in to comment.
Something went wrong with that request. Please try again.