Fixed #6014 -- More robust error handling when validating decimal fields.

Thanks, pigletto.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6746 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-11-29 19:30:38 +00:00
parent 7a166f1a1c
commit 29892d02fa
2 changed files with 6 additions and 2 deletions

View File

@ -17,7 +17,7 @@ except NameError:
from sets import Set as set
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import StrAndUnicode, smart_unicode
from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str
from util import ErrorList, ValidationError
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput
@ -235,7 +235,7 @@ class DecimalField(Field):
super(DecimalField, self).clean(value)
if not self.required and value in EMPTY_VALUES:
return None
value = str(value).strip()
value = smart_str(value).strip()
try:
value = Decimal(value)
except DecimalException:

View File

@ -323,6 +323,10 @@ Decimal("3.14")
Traceback (most recent call last):
...
ValidationError: [u'Enter a number.']
>>> f.clean(u'łąść')
Traceback (most recent call last):
...
ValidationError: [u'Enter a number.']
>>> f.clean('1.0 ')
Decimal("1.0")
>>> f.clean(' 1.0')