Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#10513 closed (fixed)

Template filter "floatformat" does not support __float__ anymore.

Reported by: Sebastian Noack Owned by: Alex Gaynor
Component: Template system Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Since django 1.0 the template filter floatformat, converts the value to unicode and after it to Decimal. So you can't pass anymore objects to floatformat, which provides a float method but not a unicode or str method.

Attachments (2)

floatfilter-__float__-regression.diff (1.1 KB ) - added by steingrd 15 years ago.
support float objects with regression test
floatfilter.diff (2.5 KB ) - added by Alex Gaynor 15 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Erin Kelly, 15 years ago

Triage Stage: UnreviewedAccepted

by steingrd, 15 years ago

support float objects with regression test

comment:2 by steingrd, 15 years ago

Has patch: set

I've attached a patch with a regression test for objects with __float__ methods and a proposed fix. Objects with __float__ methods are simply converted to floats. It passes all the tests.

comment:3 by Erin Kelly, 15 years ago

Patch needs improvement: set

The problem with the patch is that decimal objects have a __float__ method. We don't want to convert decimals to floats due to the possible loss of precision, so the code should only convert to a float if it has already failed to convert to a decimal directly.

by Alex Gaynor, 15 years ago

Attachment: floatfilter.diff added

comment:4 by Alex Gaynor, 15 years ago

milestone: 1.1
Patch needs improvement: unset

comment:5 by Alex Gaynor, 15 years ago

Owner: changed from nobody to Alex Gaynor

comment:6 by Jacob, 15 years ago

Resolution: fixed
Status: newclosed

(In [10278]) Fixed #10513: floatformat now works with floatish things, not just real floats. Thanks, Alex.

comment:7 by Jacob, 15 years ago

(In [10299]) [1.0.X] Fixed #10513: floatformat now works with floatish things, not just real floats. Thanks, Alex. Backport of [10278] from trunk.

comment:8 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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