Opened 13 years ago

Closed 10 years ago

Last modified 7 years ago

#14807 closed Uncategorized (fixed)

django.utils.formats localize_input inserts thousands_separator into boolean values

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

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 Klaas van Schelven 13 years ago.
patch.2 (1.5 KB ) - added by Klaas van Schelven 13 years ago.

Download all attachments as: .zip

Change History (15)

by Klaas van Schelven, 13 years ago

Attachment: patch added

comment:1 by Jannis Leidel, 13 years ago

Component: UncategorizedInternationalization
milestone: 1.3
Triage Stage: UnreviewedAccepted

by Klaas van Schelven, 13 years ago

Attachment: patch.2 added

comment:2 by Klaas van Schelven, 13 years ago

  • 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 by Jannis Leidel, 13 years ago

Triage Stage: AcceptedReady for checkin

Needs to be backported, too.

comment:4 by Russell Keith-Magee, 13 years ago

Resolution: fixed
Status: newclosed

(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 by Russell Keith-Magee, 13 years ago

(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 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:7 by klaas@…, 10 years ago

Easy pickings: unset
Resolution: fixed
Severity: Normal
Status: closednew
Type: Uncategorized
UI/UX: unset

When fixing this, input_localize was missed. My proposed solution (which is unfortunately not formatted as a pull request, nor does it have tests) is here:

https://github.com/vanschelven/django/commit/f0e39c83ec9174b8e5241caa6ba59b8e2e6deb66

Also copying my notes from that solution to justify reopening the issue:

6c53a81 only fixed localize(), but not localize_input()
It appears to me that this was simply an oversight at the time.

It seems that a new call-order for fields somewhere between Django 1.4
and Django 1.6 triggers triggers this bug again, but this time on the inputs
and only when rendering fields as_hidden.

comment:8 by Tim Graham, 10 years ago

Resolution: fixed
Status: newclosed

I'll be better to open a new ticket rather than reopening one that's three years old where the original fix has already been released, thanks.

in reply to:  7 comment:9 by Klaas van Schelven, 10 years ago

So was the new ticket created? Or am I expected to do this?

comment:10 by Tim Graham, 10 years ago

Please do it, thank-you.

comment:11 by Tim Graham, 8 years ago

The follow up ticket is #26173.

comment:12 by Claude Paroz <claude@…>, 7 years ago

In 68407e35:

Refs #14807 -- Removed unneeded mark_safe call

comment:13 by Claude Paroz <claude@…>, 7 years ago

In f6ea7c13:

[2.0.x] Refs #14807 -- Removed unneeded mark_safe call

Backport of 68407e3545f4b3e051c87cd530c97765bf2cdd80 from master.

Note: See TracTickets for help on using tickets.
Back to Top