#19656: FloatField localization
------------------------------------+-------------------------------------
     Reporter:  michael.anckaert@…  |      Owner:  nobody
         Type:  New feature         |     Status:  new
    Component:  Forms               |    Version:  1.4
     Severity:  Normal              |   Keywords:  FloatField Localization
 Triage Stage:  Unreviewed          |  Has patch:  1
Easy pickings:  1                   |      UI/UX:  0
------------------------------------+-------------------------------------
 Currently the localization of the forms FloatField is controlled by the
 localize parameter to the field constructor and is independent from the
 project setting USE_L10N.
 When using a FloatField on a model in combination with Class Based Views
 and a standard generated ModelForm, this produces strange results:
 Localization nl-BE for example displays floats as 3,2 but forms require
 3.2 (comma vs dot), essentially creating an unusable UpdateView.

 It would make sense to make localization default on FloatField when
 USE_L10N is on and use the localize parameter on FloatField to disable
 this.

 Below code is the modified FloatField method to_python, extra change would
 required changing default of localize in the constructor to True.

 {{{
 def to_python(self, value):
         """
         Validates that float() can be called on the input. Returns the
 result
         of float(). Returns None for empty values.
         """
         value = super(IntegerField, self).to_python(value)
         if value in validators.EMPTY_VALUES:
             return None
         if settings.USE_L10N and self.localize:
             value = formats.sanitize_separators(value)
         try:
             value = float(value)
         except (ValueError, TypeError):
             raise ValidationError(self.error_messages['invalid'])
         return value
 }}}


 This change would require additional changes to the documentation to
 reflex the automatic localization of form fields when using USE_L10N.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19656>
Django <https://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 https://groups.google.com/groups/opt_out.


Reply via email to