diff --git a/django/core/validators.py b/django/core/validators.py index 874edaefdd..e728dbc0ed 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -18,7 +18,7 @@ except ImportError: from django.conf import settings from django.utils.translation import ugettext as _, ugettext_lazy, ungettext from django.utils.functional import Promise, lazy -from django.utils.encoding import force_unicode +from django.utils.encoding import force_unicode, smart_str _datere = r'\d{4}-\d{1,2}-\d{1,2}' _timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?' @@ -451,7 +451,7 @@ class IsValidDecimal(object): "Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places def isValidFloat(field_data, all_data): - data = str(field_data) + data = smart_str(field_data) try: float(data) except ValueError: diff --git a/tests/modeltests/manipulators/models.py b/tests/modeltests/manipulators/models.py index 2ee81f62b3..c9b9848235 100644 --- a/tests/modeltests/manipulators/models.py +++ b/tests/modeltests/manipulators/models.py @@ -1,3 +1,4 @@ +# coding: utf-8 """ 27. Default manipulators @@ -21,7 +22,7 @@ class Album(models.Model): def __unicode__(self): return self.name -__test__ = {'API_TESTS':""" +__test__ = {'API_TESTS':u""" >>> from django.utils.datastructures import MultiValueDict # Create a Musician object via the default AddManipulator. @@ -88,4 +89,9 @@ True >>> a2.release_date datetime.date(2005, 2, 13) + +# Test isValidFloat Unicode coercion +>>> from django.core.validators import isValidFloat, ValidationError +>>> try: isValidFloat(u"รค", None) +... except ValidationError: pass """}