#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)
Change History (10)
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 16 years ago
Attachment: | floatfilter-__float__-regression.diff added |
---|
comment:2 by , 16 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 float
s. It passes all the tests.
comment:3 by , 16 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 , 16 years ago
Attachment: | floatfilter.diff added |
---|
comment:4 by , 16 years ago
milestone: | → 1.1 |
---|---|
Patch needs improvement: | unset |
comment:5 by , 16 years ago
Owner: | changed from | to
---|
comment:6 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
support float objects with regression test