Fixed #28711 -- Fixed unordered_list template filter with lazy translations.
This commit is contained in:
parent
b21b1b10af
commit
d997ab7764
|
@ -1,6 +1,7 @@
|
||||||
"""Default variable filters."""
|
"""Default variable filters."""
|
||||||
import random as random_module
|
import random as random_module
|
||||||
import re
|
import re
|
||||||
|
import types
|
||||||
from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation
|
from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
@ -615,7 +616,7 @@ def unordered_list(value, autoescape=True):
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
yield item, None
|
yield item, None
|
||||||
break
|
break
|
||||||
if not isinstance(next_item, str):
|
if isinstance(next_item, (list, tuple, types.GeneratorType)):
|
||||||
try:
|
try:
|
||||||
iter(next_item)
|
iter(next_item)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.template.defaultfilters import unordered_list
|
from django.template.defaultfilters import unordered_list
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from ..utils import setup
|
from ..utils import setup
|
||||||
|
|
||||||
|
@ -38,6 +39,12 @@ class FunctionTests(SimpleTestCase):
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.assertEqual(unordered_list(['item 1', 'item 2']), '\t<li>item 1</li>\n\t<li>item 2</li>')
|
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):
|
def test_nested(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
unordered_list(['item 1', ['item 1.1']]),
|
unordered_list(['item 1', ['item 1.1']]),
|
||||||
|
|
Loading…
Reference in New Issue