Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13845 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3f9054dd777a80cb6ccba0abcad8e2b43537c123 1 parent 4df57fb
Luke Plant authored September 13, 2010
4  django/template/defaultfilters.py
@@ -601,6 +601,10 @@ def convert_old_style_list(list_):
601 601
         first_item, second_item = list_
602 602
         if second_item == []:
603 603
             return [first_item], True
  604
+        try:
  605
+            it = iter(second_item)  # see if second item is iterable
  606
+        except TypeError:
  607
+            return list_, False
604 608
         old_style_list = True
605 609
         new_second_item = []
606 610
         for sublist in second_item:
11  tests/regressiontests/defaultfilters/tests.py
@@ -347,6 +347,17 @@
347 347
 >>> unordered_list(['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']])
348 348
 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>'
349 349
 
  350
+>>> class ULItem(object):
  351
+...     def __init__(self, title):
  352
+...       self.title = title
  353
+...     def __unicode__(self):
  354
+...         return u'ulitem-%s' % str(self.title)
  355
+
  356
+>>> a = ULItem('a')
  357
+>>> b = ULItem('b')
  358
+>>> unordered_list([a,b])
  359
+u'\t<li>ulitem-a</li>\n\t<li>ulitem-b</li>'
  360
+
350 361
 # Old format for unordered lists should still work
351 362
 >>> unordered_list([u'item 1', []])
352 363
 u'\t<li>item 1</li>'

0 notes on commit 3f9054d

Please sign in to comment.
Something went wrong with that request. Please try again.