Django

Code

Ticket #3176 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

Patch: Make floatformat templatetag more generally useful

Reported by: Eric Floehr <eric@intellovations.com> Assigned to: adrian
Milestone: Component: Template system
Version: SVN Keywords: MESSAGE
Cc: Jbeil Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The floatformat tag is pretty specific: it formats to one decimal place, and doesn't put a decimal if the number only has zeros past the decimal (i.e. equivalent to an integer).

I am developing an app with heavy display of floats, with different requirements including displaying different numbers of decimal places, and sometimes wanting to always display the decimal places. To solve the problem, I could create a custom tag, or make floatformat more generally useful. I chose the latter.

floatformat in the default case works as it always has. However, floatformat now can take an argument which specifies the number of decimal places. If that number is positive, it will always display the decimal places. If that number is negative, it will only display decimal places if there aren't zeros in the decimal places (i.e. equivalent to an integer).

For example, if num1 = 34.23234 and num2 = 34.00000:

        num1|floatformat results in 34.2
        num2|floatformat is 34
        num1|floatformat:3 is 34.232
        num2|floatformat:3 is 34.000
        num1|floatformat:-3 is 34.232
        num2|floatformat:-3 is 34

"|floatformat" and "|floatformat:-1" are functionally equivalent.

I hope others find this enhancement useful.

Attachments

django.template.defaultfilters.py.patch (1.6 kB) - added by Eric Floehr <eric@intellovations.com> on 12/21/06 06:42:24.
Patch to floatformat tag in django.template.defaultfilters
tests.regressiontests.defaultfilters.tests.py.patch (0.7 kB) - added by Eric Floehr <eric@intellovations.com> on 12/22/06 06:23:35.
Patch to template filter regression tests to add tests for new functionality of floatformat
docs.templates.txt.patch (1.3 kB) - added by Eric Floehr <eric@intellovations.com> on 12/22/06 06:24:11.
Patch to docs to document new functionality of floatformat

Change History

12/21/06 06:42:24 changed by Eric Floehr <eric@intellovations.com>

  • attachment django.template.defaultfilters.py.patch added.

Patch to floatformat tag in django.template.defaultfilters

12/21/06 15:05:04 changed by SmileyChris

Similar ticket: #3004

12/22/06 06:23:35 changed by Eric Floehr <eric@intellovations.com>

  • attachment tests.regressiontests.defaultfilters.tests.py.patch added.

Patch to template filter regression tests to add tests for new functionality of floatformat

12/22/06 06:24:11 changed by Eric Floehr <eric@intellovations.com>

  • attachment docs.templates.txt.patch added.

Patch to docs to document new functionality of floatformat

01/03/07 01:39:08 changed by SmileyChris

  • status changed from new to closed.
  • resolution set to fixed.

Implemented in [4274]

08/14/07 15:02:16 changed by EMUNNYUNLIP

  • cc set to Jbeil.
  • keywords changed from templatetag floatformat templates to MESSAGE.

Everybody likes sex! If you need to find beautiful local girl, click <a href=http://adultfriendfinderpersonalsfreeonli.blogspot.com/>here</a> http://adultfriendfinderpersonalsfreeonli.blogspot.com/

08/14/07 15:02:29 changed by EMUNNYUNLIP

If you like sex you need to visit it A lot of local girls need sex right <a href=http://adultfriendfinderpersonalsfreeonli.blogspot.com/>here</a> http://adultfriendfinderpersonalsfreeonli.blogspot.com/


Add/Change #3176 (Patch: Make floatformat templatetag more generally useful)




Change Properties
Action