mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed string length check in LayerMapping
This commit is contained in:
parent
7fc13178d6
commit
4dcfacb5b9
@ -31,6 +31,7 @@ class CountyFeat(NamedModel):
|
||||
|
||||
class City(NamedModel):
|
||||
name_txt = models.TextField(default='')
|
||||
name_short = models.CharField(max_length=5)
|
||||
population = models.IntegerField()
|
||||
density = models.DecimalField(max_digits=7, decimal_places=1)
|
||||
dt = models.DateField()
|
||||
|
@ -15,7 +15,7 @@ from django.utils._os import upath
|
||||
|
||||
if HAS_GDAL:
|
||||
from django.contrib.gis.utils.layermapping import (LayerMapping,
|
||||
LayerMapError, InvalidDecimal, MissingForeignKey)
|
||||
LayerMapError, InvalidDecimal, InvalidString, MissingForeignKey)
|
||||
from django.contrib.gis.gdal import DataSource
|
||||
|
||||
from .models import (
|
||||
@ -287,6 +287,13 @@ class LayerMapTest(TestCase):
|
||||
source_srs=4326)
|
||||
lm.save(silent=True)
|
||||
|
||||
def test_charfield_too_short(self):
|
||||
mapping = copy(city_mapping)
|
||||
mapping['name_short'] = 'Name'
|
||||
lm = LayerMapping(City, city_shp, mapping)
|
||||
with self.assertRaises(InvalidString):
|
||||
lm.save(silent=True, strict=True)
|
||||
|
||||
def test_textfield(self):
|
||||
"Tests that String content fits also in a TextField"
|
||||
mapping = copy(city_mapping)
|
||||
|
@ -346,9 +346,9 @@ class LayerMapping(object):
|
||||
val = force_text(ogr_field.value, self.encoding)
|
||||
else:
|
||||
val = ogr_field.value
|
||||
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)))
|
||||
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):
|
||||
try:
|
||||
# Creating an instance of the Decimal value to use.
|
||||
|
Loading…
Reference in New Issue
Block a user