Skip to content

Commit

Permalink
Fixed #18367 -- Allowed LayerMapping to store strings in TextField.
Browse files Browse the repository at this point in the history
Thanks geoffhing@gmail.com for the report.
  • Loading branch information
claudep committed May 24, 2012
1 parent f1ebcdc commit f4abba5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions django/contrib/gis/tests/layermap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CountyFeat(models.Model):

class City(models.Model):
name = models.CharField(max_length=25)
name_txt = models.TextField(default='')
population = models.IntegerField()
density = models.DecimalField(max_digits=7, decimal_places=1)
dt = models.DateField()
Expand Down
9 changes: 9 additions & 0 deletions django/contrib/gis/tests/layermap/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,12 @@ def test_invalid_layer(self):
lm = LayerMapping(Invalid, invalid_shp, invalid_mapping,
source_srs=4326)
lm.save(silent=True)

def test_textfield(self):
"Tests that String content fits also in a TextField"
mapping = copy(city_mapping)
mapping['name_txt'] = 'Name'
lm = LayerMapping(City, city_shp, mapping)
lm.save(silent=True, strict=True)
self.assertEqual(City.objects.count(), 3)
self.assertEqual(City.objects.all().order_by('name_txt')[0].name_txt, "Houston")
2 changes: 1 addition & 1 deletion django/contrib/gis/utils/layermapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def verify_ogr_field(self, ogr_field, model_field):
val = unicode(ogr_field.value, self.encoding)
else:
val = ogr_field.value
if len(val) > model_field.max_length:
if model_field.max_length and len(val) > model_field.max_length:
raise InvalidString('%s model field maximum string length is %s, given %s characters.' %
(model_field.name, model_field.max_length, len(val)))
elif isinstance(ogr_field, OFTReal) and isinstance(model_field, models.DecimalField):
Expand Down

0 comments on commit f4abba5

Please sign in to comment.