Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#16297 closed Bug (fixed)

unexpected behavior with make_list filter

Reported by: ned Owned by: teraom
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When using the make_list filter I would expect the following code to print 'foo' on the first iteration. But the conditional fails.

{% for i in 12345|make_list %}
{{i}}:
{% if 1 == i %}foo{% endif %}
{% endfor %}

Forcing the variable i to be an int with the following hack makes it work, but from reading the make_list documentation I thought it should already be an integer.

{% if 1 == i|add:0 %}foo{% endif %}

Am I missing something about the limitations of conditionals in the templating system?

Attachments (1)

make_list_integer-16297.diff (824 bytes ) - added by teraom 14 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Julien Phalip, 14 years ago

Component: Template systemDocumentation
Easy pickings: set
Triage Stage: UnreviewedAccepted

This is a bug in the documentation. make_list systematically casts the argument to a unicode string before creating the list:

>>> from django.template.defaultfilters import make_list
>>> make_list(12345)
[u'1', u'2', u'3', u'4', u'5']

comment:2 by teraom, 14 years ago

Has patch: set
Owner: changed from nobody to teraom
Status: newassigned

by teraom, 14 years ago

comment:3 by Łukasz Rekucki, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Simon Meers, 14 years ago

Resolution: fixed
Status: assignedclosed

In [16468]:

Fixed #16297 -- make_list documentation error regarding integers. Thanks ned and teraom.

comment:5 by Simon Meers, 14 years ago

In [16469]:

[1.3.X] Fixed #16297 -- make_list documentation error regarding integers. Thanks ned and teraom.

Backport of r16468 from trunk.

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