[2.0.x] Fixed #28711 -- Fixed unordered_list template filter with lazy translations.

Backport of d997ab7764 from master
This commit is contained in:
Jonas Haag 2017-10-19 00:09:19 +02:00 committed by Tim Graham
parent 673427d3fc
commit a831e4bad0
2 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,7 @@
"""Default variable filters."""
import random as random_module
import re
import types
from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation
from functools import wraps
from operator import itemgetter
@ -616,7 +617,7 @@ def unordered_list(value, autoescape=True):
except StopIteration:
yield item, None
break
if not isinstance(next_item, str):
if isinstance(next_item, (list, tuple, types.GeneratorType)):
try:
iter(next_item)
except TypeError:

View File

@ -1,6 +1,7 @@
from django.template.defaultfilters import unordered_list
from django.test import SimpleTestCase
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy
from ..utils import setup
@ -38,6 +39,12 @@ class FunctionTests(SimpleTestCase):
def test_list(self):
self.assertEqual(unordered_list(['item 1', 'item 2']), '\t<li>item 1</li>\n\t<li>item 2</li>')
def test_list_gettext(self):
self.assertEqual(
unordered_list(['item 1', gettext_lazy('item 2')]),
'\t<li>item 1</li>\n\t<li>item 2</li>'
)
def test_nested(self):
self.assertEqual(
unordered_list(['item 1', ['item 1.1']]),