[Django] #22798: pluralize filter should pluralize float/Decimal values between 1 and 2

11 views
Skip to first unread message

Django

unread,
Jun 9, 2014, 5:42:21 AM6/9/14
to django-...@googlegroups.com
#22798: pluralize filter should pluralize float/Decimal values between 1 and 2
---------------------------------+--------------------
Reporter: Odd_Bloke | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
The pluralize filter works as expected for floats/Decimals outside of the
range 1-2:

{{{
>>> pluralize(0.9)
u's'
>>> pluralize(2.1)
u's'
}}}

However, when applied to a decimal number between 1 and 2, it
(incorrectly) does not pluralize:

{{{
>>> pluralize(1.2)
u''
}}}

Not only is this incorrect from an English standpoint, it also contradicts
pluralize's docstring: "Returns a plural suffix if the value is not 1."

The problem appears to be at
[https://github.com/django/django/blob/master/django/template/defaultfilters.py#L937
line 937] where the given value is converted directly to an integer; this
chops the decimal part of the number off, making it appear to be 1.

The specific use case for this is:

{{{
{{ widget_count|floatformat:"-2" }} widget{{ widget_count|pluralize }}
}}}

This will produce "0.5 widgets", "1 widget", and "2.1 widgets" correctly,
but "1.2 widget" incorrectly.


(This ticket is a descendant of #16723, but that ticket was about a
broader issue that encompassed this, and so ended up being closed as
invalid.)

--
Ticket URL: <https://code.djangoproject.com/ticket/22798>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 9, 2014, 9:43:41 AM6/9/14
to django-...@googlegroups.com
#22798: pluralize filter should pluralize float/Decimal values between 1 and 2
---------------------------------+------------------------------------

Reporter: Odd_Bloke | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Aaah now I get it. Yes, the current behaviour should be changed for
decimals when `1 < d < 2`. Sorry for closing incorrectly the other ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/22798#comment:1>

Django

unread,
Jun 10, 2014, 2:30:09 PM6/10/14
to django-...@googlegroups.com
#22798: pluralize filter should pluralize float/Decimal values between 1 and 2
---------------------------------+------------------------------------

Reporter: Odd_Bloke | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by mardini):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/2789
Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/22798#comment:2>

Django

unread,
Jun 10, 2014, 4:05:15 PM6/10/14
to django-...@googlegroups.com
#22798: pluralize filter should pluralize float/Decimal values between 1 and 2
---------------------------------+------------------------------------
Reporter: Odd_Bloke | Owner: nobody
Type: Bug | Status: closed

Component: Template system | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"868ff4e37c1e4cfaf7283496c24f6e711ad66005"]:
{{{
#!CommitTicketReference repository=""
revision="868ff4e37c1e4cfaf7283496c24f6e711ad66005"
Fixed #22798 -- `pluralize()` now adds plural_suffix for any `1 < d < 2`

Thanks Odd_Bloke for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22798#comment:3>

Reply all
Reply to author
Forward
0 new messages