[1.8.x] Fixed #25031 -- Fixed a regression in the unordered_list template filter.
Backport of e291fc4757
from master
This commit is contained in:
parent
4296801463
commit
fd61ce3817
|
@ -681,22 +681,27 @@ def unordered_list(value, autoescape=True):
|
||||||
|
|
||||||
def walk_items(item_list):
|
def walk_items(item_list):
|
||||||
item_iterator = iter(item_list)
|
item_iterator = iter(item_list)
|
||||||
for item in item_iterator:
|
try:
|
||||||
try:
|
item = next(item_iterator)
|
||||||
next_item = next(item_iterator)
|
while True:
|
||||||
except StopIteration:
|
|
||||||
next_item = None
|
|
||||||
if not isinstance(next_item, six.string_types):
|
|
||||||
try:
|
try:
|
||||||
iter(next_item)
|
next_item = next(item_iterator)
|
||||||
except TypeError:
|
except StopIteration:
|
||||||
pass
|
yield item, None
|
||||||
else:
|
break
|
||||||
yield item, next_item
|
if not isinstance(next_item, six.string_types):
|
||||||
continue
|
try:
|
||||||
yield item, None
|
iter(next_item)
|
||||||
if next_item:
|
except TypeError:
|
||||||
yield next_item, None
|
pass
|
||||||
|
else:
|
||||||
|
yield item, next_item
|
||||||
|
item = next(item_iterator)
|
||||||
|
continue
|
||||||
|
yield item, None
|
||||||
|
item = next_item
|
||||||
|
except StopIteration:
|
||||||
|
pass
|
||||||
|
|
||||||
def list_formatter(item_list, tabs=1):
|
def list_formatter(item_list, tabs=1):
|
||||||
indent = '\t' * tabs
|
indent = '\t' * tabs
|
||||||
|
|
|
@ -89,3 +89,6 @@ Bugfixes
|
||||||
* Fixed inline forms that use a parent object that has a ``UUIDField`` primary
|
* Fixed inline forms that use a parent object that has a ``UUIDField`` primary
|
||||||
key and a child object that has an ``AutoField`` primary key
|
key and a child object that has an ``AutoField`` primary key
|
||||||
(:ticket:`24958`).
|
(:ticket:`24958`).
|
||||||
|
|
||||||
|
* Fixed a regression in the ``unordered_list`` template filter on certain
|
||||||
|
inputs (:ticket:`25031`).
|
||||||
|
|
|
@ -83,6 +83,13 @@ class FunctionTests(SimpleTestCase):
|
||||||
'</li>\n\t</ul>\n\t</li>\n\t<li>item 2</li>',
|
'</li>\n\t</ul>\n\t</li>\n\t<li>item 2</li>',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_nested3(self):
|
||||||
|
self.assertEqual(
|
||||||
|
unordered_list(['item 1', 'item 2', ['item 2.1']]),
|
||||||
|
'\t<li>item 1</li>\n\t<li>item 2\n\t<ul>\n\t\t<li>item 2.1'
|
||||||
|
'</li>\n\t</ul>\n\t</li>',
|
||||||
|
)
|
||||||
|
|
||||||
def test_nested_multiple(self):
|
def test_nested_multiple(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
unordered_list(['item 1', ['item 1.1', ['item 1.1.1', ['item 1.1.1.1']]]]),
|
unordered_list(['item 1', ['item 1.1', ['item 1.1.1', ['item 1.1.1.1']]]]),
|
||||||
|
|
Loading…
Reference in New Issue