summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2010-09-13 22:34:39 +0000
committerLuke Plant <L.Plant.98@cantab.net>2010-09-13 22:34:39 +0000
commit93e83546a35f268a4bbf0a9b30186fc4ee1b0885 (patch)
treea34157f099eba652d9a4111778f182e052c6c758
parent21f60e9fa92dab7d80fbf47e97c1bd92a4f10382 (diff)
[1.2.X] Fixed #12965 - unordered_list template filter fails when given a non-iterable second item in a two item list
Thanks to grahamu for the report and patch. Backport of [13845] from trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13846 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/defaultfilters.py4
-rw-r--r--tests/regressiontests/defaultfilters/tests.py11
2 files changed, 15 insertions, 0 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 1e58ff71ca..80002c3b0b 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -601,6 +601,10 @@ def unordered_list(value, autoescape=None):
first_item, second_item = list_
if second_item == []:
return [first_item], True
+ try:
+ it = iter(second_item) # see if second item is iterable
+ except TypeError:
+ return list_, False
old_style_list = True
new_second_item = []
for sublist in second_item:
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index 25555081e4..ff49b65d68 100644
--- a/tests/regressiontests/defaultfilters/tests.py
+++ b/tests/regressiontests/defaultfilters/tests.py
@@ -347,6 +347,17 @@ u'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1\n\t\t<ul>\n\t\t\t<li>item 1.1.1\n\t\t\t
>>> unordered_list(['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']])
u'\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>'
+>>> class ULItem(object):
+... def __init__(self, title):
+... self.title = title
+... def __unicode__(self):
+... return u'ulitem-%s' % str(self.title)
+
+>>> a = ULItem('a')
+>>> b = ULItem('b')
+>>> unordered_list([a,b])
+u'\t<li>ulitem-a</li>\n\t<li>ulitem-b</li>'
+
# Old format for unordered lists should still work
>>> unordered_list([u'item 1', []])
u'\t<li>item 1</li>'