Ticket #9664: layermapping_mysql.diff
File layermapping_mysql.diff, 5.3 KB (added by , 16 years ago) |
---|
-
django/contrib/gis/utils/layermapping.py
116 116 OGRException, OGRGeometry, OGRGeomType, SpatialReference 117 117 from django.contrib.gis.gdal.field import \ 118 118 OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime 119 from django.contrib.gis.models import GeometryColumns, SpatialRefSys120 119 from django.db import models, transaction 121 120 from django.contrib.localflavor.us.models import USStateField 122 121 … … 189 188 190 189 # Getting the geometry column associated with the model (an 191 190 # exception will be raised if there is no geometry column). 192 self.geo_col = self.geometry_column() 191 if SpatialBackend.mysql: 192 transform = False 193 else: 194 self.geo_col = self.geometry_column() 193 195 194 196 # Checking the source spatial reference system, and getting 195 197 # the coordinate transformation object (unless the `transform` … … 327 329 328 330 def check_srs(self, source_srs): 329 331 "Checks the compatibility of the given spatial reference object." 332 from django.contrib.gis.models import SpatialRefSys 330 333 if isinstance(source_srs, SpatialReference): 331 334 sr = source_srs 332 335 elif isinstance(source_srs, SpatialRefSys): … … 498 501 #### Other model methods #### 499 502 def coord_transform(self): 500 503 "Returns the coordinate transformation object." 504 from django.contrib.gis.models import SpatialRefSys 501 505 try: 502 506 # Getting the target spatial reference system 503 507 target_srs = SpatialRefSys.objects.get(srid=self.geo_col.srid).srs … … 509 513 510 514 def geometry_column(self): 511 515 "Returns the GeometryColumn model associated with the geographic column." 516 from django.contrib.gis.models import GeometryColumns 512 517 # Getting the GeometryColumn object. 513 518 try: 514 519 db_table = self.model._meta.db_table 515 520 geo_col = self.geom_field 516 if SpatialBackend. name == 'oracle':521 if SpatialBackend.oracle: 517 522 # Making upper case for Oracle. 518 523 db_table = db_table.upper() 519 524 geo_col = geo_col.upper() -
django/contrib/gis/tests/__init__.py
29 29 elif postgis: 30 30 test_models += ['distapp', 'layermap', 'relatedapp'] 31 31 elif mysql: 32 test_models += ['relatedapp' ]32 test_models += ['relatedapp', 'layermap'] 33 33 34 34 test_suite_names += [ 35 35 'test_gdal_driver', -
django/contrib/gis/tests/layermap/tests.py
1 1 import os, unittest 2 2 from copy import copy 3 from datetime import date4 3 from decimal import Decimal 5 4 from models import City, County, CountyFeat, Interstate, State, city_mapping, co_mapping, cofeat_mapping, inter_mapping 5 from django.contrib.gis.db.backend import SpatialBackend 6 6 from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError, InvalidDecimal, MissingForeignKey 7 7 from django.contrib.gis.gdal import DataSource 8 8 … … 85 85 lm = LayerMapping(Interstate, inter_shp, inter_mapping) 86 86 lm.save(silent=True, strict=True) 87 87 except InvalidDecimal: 88 pass 88 # No transactions for geoms on MySQL; delete added features. 89 if SpatialBackend.mysql: Interstate.objects.all().delete() 89 90 else: 90 91 self.fail('Should have failed on strict import with invalid decimal values.') 91 92 … … 151 152 self.assertRaises(e, LayerMapping, County, co_shp, co_mapping, transform=False, unique=arg) 152 153 153 154 # No source reference system defined in the shapefile, should raise an error. 154 self.assertRaises(LayerMapError, LayerMapping, County, co_shp, co_mapping) 155 if not SpatialBackend.mysql: 156 self.assertRaises(LayerMapError, LayerMapping, County, co_shp, co_mapping) 155 157 156 158 # Passing in invalid ForeignKey mapping parameters -- must be a dictionary 157 159 # mapping for the model the ForeignKey points to. … … 227 229 lm.save(fid_range=slice(None, 1), silent=True, strict=True) # layer[:1] 228 230 229 231 # Only Pueblo & Honolulu counties should be present because of 230 # the `unique` keyword. 231 qs = County.objects.all() 232 # the `unique` keyword. Have to set `order_by` on this QuerySet 233 # or else MySQL will return a different ordering than the other dbs. 234 qs = County.objects.order_by('name') 232 235 self.assertEqual(2, qs.count()) 233 236 hi, co = tuple(qs) 234 237 hi_idx, co_idx = tuple(map(NAMES.index, ('Honolulu', 'Pueblo'))) -
django/contrib/gis/tests/layermap/tests_mysql.py
1 from tests import *