Ticket #16537: 16537.2.diff

File 16537.2.diff, 2.6 KB (added by jbronn, 13 years ago)
  • django/contrib/gis/utils/layermapping.py

    diff -r 64ec0b7000d1 django/contrib/gis/utils/layermapping.py
    a b  
    393393
    394394        # Attempting to retrieve and return the related model.
    395395        try:
    396             return rel_model.objects.get(**fk_kwargs)
     396            return rel_model.objects.using(self.using).get(**fk_kwargs)
    397397        except ObjectDoesNotExist:
    398398            raise MissingForeignKey('No ForeignKey %s model found with keyword arguments: %s' % (rel_model.__name__, fk_kwargs))
    399399
     
    429429        SpatialRefSys = self.spatial_backend.spatial_ref_sys()
    430430        try:
    431431            # Getting the target spatial reference system
    432             target_srs = SpatialRefSys.objects.get(srid=self.geo_field.srid).srs
     432            target_srs = SpatialRefSys.objects.using(self.using).get(srid=self.geo_field.srid).srs
    433433
    434434            # Creating the CoordTransform object
    435435            return CoordTransform(self.source_srs, target_srs)
  • django/contrib/gis/utils/srs.py

    diff -r 64ec0b7000d1 django/contrib/gis/utils/srs.py
    a b  
    11from django.contrib.gis.gdal import SpatialReference
    2 from django.db import connections, DEFAULT_DB_ALIAS
    32
    43def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
    5                   database=DEFAULT_DB_ALIAS):
     4                  database=None):
    65    """
    76    This function takes a GDAL SpatialReference system and adds its information
    87    to the `spatial_ref_sys` table of the spatial backend.  Doing this enables
     
    3332      of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, it's value
    3433      is 'default').
    3534    """
     35    from django.db import connections, DEFAULT_DB_ALIAS
     36    if not database:
     37        database = DEFAULT_DB_ALIAS
    3638    connection = connections[database]
     39
    3740    if not hasattr(connection.ops, 'spatial_version'):
    3841        raise Exception('The `add_srs_entry` utility only works '
    3942                        'with spatial backends.')
     
    6972    try:
    7073        # Try getting via SRID only, because using all kwargs may
    7174        # 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)
    7376    except SpatialRefSys.DoesNotExist:
    74         sr = SpatialRefSys.objects.create(**kwargs)
     77        sr = SpatialRefSys.objects.using(database).create(**kwargs)
    7578
    7679# Alias is for backwards-compatibility purposes.
    7780add_postgis_srs = add_srs_entry
Back to Top