#14101: Localized DecimalField doesn't accept localized input
-------------------------------------------+--------------------------------
Reporter: dfoerster | Owner: nobody
Status: new | Milestone:
Component: Internationalization | Version: 1.2
Resolution: | Keywords: localize
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------------------+--------------------------------
Comment (by michelts):
I'm having similar problems. I'm using the pt_BR language code.
First I tested with django.1.2.3 and trunk version. I make a model form
with datetime fields and decimal fields. The tests run as follow:
== Django 1.2.3 ==
* datetime fields input: ok
* datetime fields output: ok
* decimal fields input: ok
* decimal fields output: not ok
When using a form for an instance, the original values are not filled
properly according the locale set. It can be fixed by adding a
"prepare_value" method on the DecimalField class to convert the original
output.
Anyway, even making this change, the correct value will only be picked if
the Field instance has the localize attribute set to true. I think it
should localize it always if the USE_L10N is set to true. This way, the
Field should call the number_format and sanitize_separators methods
always, these methods can decide is they will convert (USE_L10N is on) or
not convert (USE_L10N is off) the value.
== Django trunk ==
* datetime fields input: ok
* datetime fields output: not ok
* decimal fields input: ok
* decimal fields output: not ok
In the trunk, even the datetime output is not correct. The problem is
another one.
There was a fix on the way the formats modules was get, it is now cached.
Some code was broken during the cache implementation and this way, a
generic language is used in prior of a specific one when the oppose is
expected (e. g. pt is used in prior of pt_BR).
This way, I think there is 3 bugs on this topic:
1. the DecimalField class should have a prepare_value method to localize
the number if needed;
2. the DecimalField to_python method should call sanitize_separators
always, this method will act only if the USE_L10N is on;
3. the order of the language picked by the get_format /
get_format_modules should be fixed to priorize specific languages;
I can do the work if you agree with my proposes.
Best regards!
--
Ticket URL: <http://code.djangoproject.com/ticket/14101#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.