From a831e4bad0e5f616680955dfd63a38fa49d8086b Mon Sep 17 00:00:00 2001 From: Jonas Haag Date: Thu, 19 Oct 2017 00:09:19 +0200 Subject: [PATCH] [2.0.x] Fixed #28711 -- Fixed unordered_list template filter with lazy translations. Backport of d997ab776477dd9ecb158229b2622c7f1ed93dfb from master --- django/template/defaultfilters.py | 3 ++- tests/template_tests/filter_tests/test_unordered_list.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index b172be6239..935fcdff8e 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -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: diff --git a/tests/template_tests/filter_tests/test_unordered_list.py b/tests/template_tests/filter_tests/test_unordered_list.py index c3fa3bd4d0..6a04664d99 100644 --- a/tests/template_tests/filter_tests/test_unordered_list.py +++ b/tests/template_tests/filter_tests/test_unordered_list.py @@ -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
  • item 1
  • \n\t
  • item 2
  • ') + def test_list_gettext(self): + self.assertEqual( + unordered_list(['item 1', gettext_lazy('item 2')]), + '\t
  • item 1
  • \n\t
  • item 2
  • ' + ) + def test_nested(self): self.assertEqual( unordered_list(['item 1', ['item 1.1']]),