{{{#!python
AGE_BRACKET = (
# The value in the first column will be saved in Postgres Range field,
# so the upper boundary is not counted, i.e for (18, 25) range, the
value 25
# is not counted.
((None, 18), _('Under 18')),
((18, 25), _('18 - 24')),
((25, 36), _('25 - 35')),
((36, 46), _('36 - 45')),
((46, 56), _('46 - 55')),
((46, 66), _('56 - 65')),
((66, None), _('Above 65')),
)
}}}
However, when being rendered as form, all values become empty string. This
happens since Django 1.11. In Django 1.10, it was OK.
I found the cause is the widget template ''select_option.html''
{{{#!django
<option value="{{ widget.value|stringformat:'s' }}"{% include
"django/forms/widgets/attrs.html" %}>{{ widget.label }}</option>
}}}
The `stringformat` filter turns every non-string value to empty string.
My suggestion is that, update `stringformat` so that it returns
`str(value)` if value is not a string. Is it right way to do?
--
Ticket URL: <https://code.djangoproject.com/ticket/28502>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* version: 1.11 => master
* component: Forms => Template system
* stage: Unreviewed => Accepted
Comment:
I also think that `stringformat` should be improved to accept tuples as
its base `value`. In Python the printf syntax special cases tuples as it
considers them as a list of placeholder values. This does not make sense
in `stringformat` as the string containing the placeholder is always a
single placeholder.
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:1>
* owner: nobody => Srinivas Reddy Thatiparthy
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:2>
Comment (by Srinivas Reddy Thatiparthy):
PR - https://github.com/django/django/pull/8914
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:3>
* has_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:4>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:5>
Comment (by Claude Paroz <claude@…>):
In [changeset:"a64f88f5be0f680a7261b500fd9243501e6a7745" a64f88f]:
{{{
#!CommitTicketReference repository=""
revision="a64f88f5be0f680a7261b500fd9243501e6a7745"
Refs #28502 -- Completed stringformat filter tests
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"4ead705cb3cf04bb7551ac037d1e11f682b62bcf" 4ead705c]:
{{{
#!CommitTicketReference repository=""
revision="4ead705cb3cf04bb7551ac037d1e11f682b62bcf"
Fixed #28502 -- Made stringformat template filter accept tuples
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"ed77bea58274e11e5a9e4c8b9650f50deb8a2b26" ed77bea]:
{{{
#!CommitTicketReference repository=""
revision="ed77bea58274e11e5a9e4c8b9650f50deb8a2b26"
Refs #28502 -- Complemented stringformat tuple handling/test.
An additional test and a code change were suggested in a late review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"dd82f1df556561233eab6a4a2032c2bb306dec87" dd82f1df]:
{{{
#!CommitTicketReference repository=""
revision="dd82f1df556561233eab6a4a2032c2bb306dec87"
[1.11.x] Fixed #28502 -- Made stringformat template filter accept tuples.
Backport of 4ead705cb3cf04bb7551ac037d1e11f682b62bcf and
ed77bea58274e11e5a9e4c8b9650f50deb8a2b26 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28502#comment:10>