Refs #23261 -- Removed old style list syntax for unordered_list filter
Per deprecation timeline.
This commit is contained in:
parent
27b2321793
commit
9a3dfa2a52
|
@ -3,7 +3,6 @@ from __future__ import unicode_literals
|
|||
|
||||
import random as random_module
|
||||
import re
|
||||
import warnings
|
||||
from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation
|
||||
from functools import wraps
|
||||
from pprint import pformat
|
||||
|
@ -11,7 +10,6 @@ from pprint import pformat
|
|||
from django.conf import settings
|
||||
from django.utils import formats, six
|
||||
from django.utils.dateformat import format, time_format
|
||||
from django.utils.deprecation import RemovedInDjango110Warning
|
||||
from django.utils.encoding import force_text, iri_to_uri
|
||||
from django.utils.html import (
|
||||
avoid_wrapping, conditional_escape, escape, escapejs, linebreaks,
|
||||
|
@ -650,37 +648,6 @@ def unordered_list(value, autoescape=True):
|
|||
else:
|
||||
escaper = lambda x: x
|
||||
|
||||
def convert_old_style_list(list_):
|
||||
"""
|
||||
Converts old style lists to the new easier to understand format.
|
||||
|
||||
The old list format looked like:
|
||||
['Item 1', [['Item 1.1', []], ['Item 1.2', []]]
|
||||
|
||||
And it is converted to:
|
||||
['Item 1', ['Item 1.1', 'Item 1.2]]
|
||||
"""
|
||||
if not isinstance(list_, (tuple, list)) or len(list_) != 2:
|
||||
return list_, False
|
||||
first_item, second_item = list_
|
||||
if second_item == []:
|
||||
return [first_item], True
|
||||
try:
|
||||
# see if second item is iterable
|
||||
iter(second_item)
|
||||
except TypeError:
|
||||
return list_, False
|
||||
old_style_list = True
|
||||
new_second_item = []
|
||||
for sublist in second_item:
|
||||
item, old_style_list = convert_old_style_list(sublist)
|
||||
if not old_style_list:
|
||||
break
|
||||
new_second_item.extend(item)
|
||||
if old_style_list:
|
||||
second_item = new_second_item
|
||||
return [first_item, second_item], old_style_list
|
||||
|
||||
def walk_items(item_list):
|
||||
item_iterator = iter(item_list)
|
||||
try:
|
||||
|
@ -717,12 +684,6 @@ def unordered_list(value, autoescape=True):
|
|||
indent, escaper(force_text(item)), sublist))
|
||||
return '\n'.join(output)
|
||||
|
||||
value, converted = convert_old_style_list(value)
|
||||
if converted:
|
||||
warnings.warn(
|
||||
"The old style syntax in `unordered_list` is deprecated and will "
|
||||
"be removed in Django 1.10. Use the the new format instead.",
|
||||
RemovedInDjango110Warning)
|
||||
return mark_safe(list_formatter(value))
|
||||
|
||||
|
||||
|
|
|
@ -2231,12 +2231,6 @@ contains ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``, then
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
.. deprecated:: 1.8
|
||||
|
||||
An older, more restrictive and verbose input format is also supported:
|
||||
``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``.
|
||||
Support for this syntax will be removed in Django 1.10.
|
||||
|
||||
.. templatefilter:: upper
|
||||
|
||||
upper
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from django.template.defaultfilters import unordered_list
|
||||
from django.test import SimpleTestCase, ignore_warnings
|
||||
from django.utils.deprecation import RemovedInDjango110Warning
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
|
@ -14,7 +13,6 @@ class UnorderedListTests(SimpleTestCase):
|
|||
output = self.engine.render_to_string('unordered_list01', {'a': ['x>', ['<y']]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango110Warning)
|
||||
@setup({'unordered_list02': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list02(self):
|
||||
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', ['<y']]})
|
||||
|
@ -36,35 +34,6 @@ class UnorderedListTests(SimpleTestCase):
|
|||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango110Warning)
|
||||
class DeprecatedUnorderedListSyntaxTests(SimpleTestCase):
|
||||
|
||||
@setup({'unordered_list01': '{{ a|unordered_list }}'})
|
||||
def test_unordered_list01(self):
|
||||
output = self.engine.render_to_string('unordered_list01', {'a': ['x>', [['<y', []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list02': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list02(self):
|
||||
output = self.engine.render_to_string('unordered_list02', {'a': ['x>', [['<y', []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list03': '{{ a|unordered_list }}'})
|
||||
def test_unordered_list03(self):
|
||||
output = self.engine.render_to_string('unordered_list03', {'a': ['x>', [[mark_safe('<y'), []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list04': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list04(self):
|
||||
output = self.engine.render_to_string('unordered_list04', {'a': ['x>', [[mark_safe('<y'), []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
@setup({'unordered_list05': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'})
|
||||
def test_unordered_list05(self):
|
||||
output = self.engine.render_to_string('unordered_list05', {'a': ['x>', [['<y', []]]]})
|
||||
self.assertEqual(output, '\t<li>x>\n\t<ul>\n\t\t<li><y</li>\n\t</ul>\n\t</li>')
|
||||
|
||||
|
||||
class FunctionTests(SimpleTestCase):
|
||||
|
||||
def test_list(self):
|
||||
|
@ -171,27 +140,3 @@ class FunctionTests(SimpleTestCase):
|
|||
unordered_list(item_generator(), autoescape=False),
|
||||
'\t<li>ulitem-a</li>\n\t<li>ulitem-b</li>\n\t<li>ulitem-<a>c</a></li>',
|
||||
)
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango110Warning)
|
||||
def test_legacy(self):
|
||||
"""
|
||||
Old format for unordered lists should still work
|
||||
"""
|
||||
self.assertEqual(unordered_list(['item 1', []]), '\t<li>item 1</li>')
|
||||
|
||||
self.assertEqual(
|
||||
unordered_list(['item 1', [['item 1.1', []]]]),
|
||||
'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t</ul>\n\t</li>',
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
unordered_list(['item 1', [['item 1.1', []],
|
||||
['item 1.2', []]]]), '\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1'
|
||||
'</li>\n\t\t<li>item 1.2</li>\n\t</ul>\n\t</li>',
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
unordered_list(['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]),
|
||||
'\t<li>States\n\t<ul>\n\t\t<li>Kansas\n\t\t<ul>\n\t\t\t<li>Lawrence</li>'
|
||||
'\n\t\t\t<li>Topeka</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>Illinois</li>\n\t</ul>\n\t</li>',
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue