Changeset 6708
- Timestamp:
- 11/20/07 09:13:55 (8 months ago)
- Files:
-
- django/branches/gis/django/contrib/gis/tests/layermap/interstates/interstates.dbf (modified) (previous)
- django/branches/gis/django/contrib/gis/tests/layermap/interstates/interstates.shp (modified) (previous)
- django/branches/gis/django/contrib/gis/tests/layermap/interstates/interstates.shx (modified) (previous)
- django/branches/gis/django/contrib/gis/tests/layermap/models.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/tests/layermap/tests.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/utils/layermapping.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/tests/layermap/models.py
r6687 r6708 11 11 class Interstate(models.Model): 12 12 name = models.CharField(max_length=20) 13 length = models.DecimalField(max_digits= 7, decimal_places=2)13 length = models.DecimalField(max_digits=6, decimal_places=2) 14 14 path = models.LineStringField() 15 15 objects = models.GeoManager() django/branches/gis/django/contrib/gis/tests/layermap/tests.py
r6687 r6708 89 89 lm.save() 90 90 91 # Only oneinterstate should have imported correctly.92 self.assertEqual( 1, Interstate.objects.count())91 # Two interstate should have imported correctly. 92 self.assertEqual(2, Interstate.objects.count()) 93 93 94 # Verifying the values in the single featurew/the model.94 # Verifying the values in the layer w/the model. 95 95 ds = DataSource(inter_shp) 96 feat = ds[0][0] 97 istate = Interstate.objects.get(name=feat['Name'].value) 98 self.assertEqual(Decimal(str(feat['Length'])), istate.length) 99 for p1, p2 in zip(feat.geom, istate.path): 100 self.assertAlmostEqual(p1[0], p2[0], 6) 101 self.assertAlmostEqual(p1[1], p2[1], 6) 96 97 # Only the first two features of this shapefile are valid. 98 valid_feats = ds[0][:2] 99 for feat in valid_feats: 100 istate = Interstate.objects.get(name=feat['Name'].value) 101 102 if feat.fid == 0: 103 self.assertEqual(Decimal(str(feat['Length'])), istate.length) 104 elif feat.fid == 1: 105 # Everything but the first two decimal digits were truncated, 106 # because the Interstate model's `length` field has decimal_places=2. 107 self.assertAlmostEqual(feat.get('Length'), float(istate.length), 2) 108 109 for p1, p2 in zip(feat.geom, istate.path): 110 self.assertAlmostEqual(p1[0], p2[0], 6) 111 self.assertAlmostEqual(p1[1], p2[1], 6) 102 112 103 113 def suite(): django/branches/gis/django/contrib/gis/utils/layermapping.py
r6687 r6708 395 395 except: 396 396 raise InvalidDecimal('Could not construct decimal from: %s' % fld) 397 398 # Getting the decimal value as a tuple. 397 399 dtup = d.as_tuple() 398 if len(dtup[1]) > field_class.max_digits: 399 raise InvalidDecimal('More than the maximum # of digits encountered.') 400 elif len(dtup[1][dtup[2]:]) > field_class.decimal_places: 401 raise InvalidDecimal('More than the maximum # of decimal places encountered.') 400 digits = dtup[1] 401 d_idx = dtup[2] # index where the decimal is 402 403 # Maximum amount of precision, or digits to the left of the decimal. 404 max_prec = field_class.max_digits - field_class.decimal_places 405 406 # Getting the digits to the left of the decimal place for the 407 # given decimal. 408 if d_idx < 0: 409 n_prec = len(digits[:d_idx]) 410 else: 411 n_prec = len(digits) + d_idx 412 413 # If we have more than the maximum digits allowed, then throw an 414 # InvalidDecimal exception. 415 if n_prec > max_prec: 416 raise InvalidDecimal('A DecimalField with max_digits %d, decimal_places %d must round to an absolute value less than 10^%d.' % 417 (field_class.max_digits, field_class.decimal_places, max_prec)) 402 418 val = d 403 419 else: … … 468 484 print 'Ignoring Feature ID %s because: %s' % (feat.fid, msg) 469 485 else: 470 # Constructing the model using the constructedkeyword args486 # Constructing the model using the keyword args 471 487 if all_prepped: 472 488 m = self.model(**kwargs)
