Use safe filter on choices used in {% for x in y %} #34

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Pertaining to issue #33:

When an integer is used as a choice value with MultipleChoiceField, the CheckBoxSelectMultijple template has a unicode/string mismatch that prevents initial values from getting rendered.

This is due to Django behavior (either intended or otherwise), and this fix works around the problem by using the safe filter, which has the side-effect of coercing the value to unicode. This will not be a security threat as the value is not being rendered into the form, but is instead passed as an argument to a template tag.

For an illustration... in Python:

>>> '1' in ['1']
True
>>> '1' in [u'1']
True

The Django template tag {% if choice.0 in field.value %}, however, does not display the same symmetry.

@danielnaab danielnaab Use safe filter on checkbox value. This will force coercion to unicod…
…e to work around a Django {% for x in y %} deficiency.
41ebed3

maraujop closed this Apr 3, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment