diff options
| author | Jannis Leidel <jannis@leidel.info> | 2010-03-01 10:19:24 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2010-03-01 10:19:24 +0000 |
| commit | 0d2a24fd4234d2c6551179b1ef4694229602ba90 (patch) | |
| tree | 85b9a03afa8b6f3cdde17deda451a58c45b7eb8a /django/utils/formats.py | |
| parent | 284e7e3cbdc1b0efb46f35485194d6a5f9b201dc (diff) | |
Fixed #12779 - Sanitize numeric form field input according to decimal and thousand separator settings.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12625 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/formats.py')
| -rw-r--r-- | django/utils/formats.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/django/utils/formats.py b/django/utils/formats.py index 88f744b96d..31027abd23 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -109,3 +109,22 @@ def localize_input(value, default=None): format = smart_str(default or get_format('TIME_INPUT_FORMATS')[0]) return value.strftime(format) return value + +def sanitize_separators(value): + """ + Sanitizes a value according to the current decimal and + thousand separator setting. Used with form field input. + """ + if settings.USE_L10N: + decimal_separator = get_format('DECIMAL_SEPARATOR') + if isinstance(value, basestring): + parts = [] + if decimal_separator in value: + value, decimals = value.split(decimal_separator, 1) + parts.append(decimals) + if settings.USE_THOUSAND_SEPARATOR: + parts.append(value.replace(get_format('THOUSAND_SEPARATOR'), '')) + else: + parts.append(value) + value = '.'.join(reversed(parts)) + return value |
