Fixed #28711 -- Fixed unordered_list template filter with lazy translations.

This commit is contained in:
Jonas Haag 2017-10-19 00:09:19 +02:00 committed by Tim Graham
parent b21b1b10af
commit d997ab7764
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
@ -615,7 +616,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 ugettext_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', ugettext_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']]),