Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#14807 closed (fixed)

django.utils.formats localize_input inserts thousands_separator into boolean values

Reported by: vanschelven Owned by: nobody
Component: Internationalization Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

formats.localize_input(True)

I'm working in an environment where I've localized all my forms (set localize=True on all fields). I also have the USE_THOUSAND_SEPARATOR = True.

This results the value attr in my booleanfield to be set to "T,rue" (Dutch) or "T.rue" (US).

The ultimate culprit is django.utils.formats localize_input

There is a check there like so:

    if isinstance(value, (decimal.Decimal, float, int, long)):

which evaluates to True for Booleans (because booleans are ints, see "issubclass(bool, int)")

I do not currently have the time to provide tests etc. I do have a simple patch

Attachments (2)

patch (679 bytes) - added by vanschelven 3 years ago.
patch.2 (1.5 KB) - added by vanschelven 3 years ago.

Download all attachments as: .zip

Change History (8)

Changed 3 years ago by vanschelven

comment:1 Changed 3 years ago by jezdez

  • Component changed from Uncategorized to Internationalization
  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 3 years ago by vanschelven

comment:2 Changed 3 years ago by vanschelven

  • Added a patch, including a test this time. And still returning unicode for booleans (just not broken unicode)
  • Turns out the problem also surfaces in more general settings (i.e. just printing booleans on screen).

comment:3 Changed 3 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

Needs to be backported, too.

comment:4 Changed 3 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [14804]) Fixed #14807 -- Ensure that boolean values aren't localized as T.rue and Fa.lse because of the thousand separator. Thanks to vanschelven for the report and patch.

comment:5 Changed 3 years ago by russellm

(In [14807]) [1.2.X] Fixed #14807 -- Ensure that boolean values aren't localized as T.rue and Fa.lse because of the thousand separator. Thanks to vanschelven for the report and

Backport of r14804 from trunk.

comment:6 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.