Ticket #12965: unordered_list.diff

File unordered_list.diff, 1.5 KB (added by Graham Ullrich, 15 years ago)
  • django/template/defaultfilters.py

     
    602602        first_item, second_item = list_
    603603        if second_item == []:
    604604            return [first_item], True
     605        try:
     606            it = iter(second_item)  # see if second item is iterable
     607        except TypeError:
     608            return list_, False   
    605609        old_style_list = True
    606610        new_second_item = []
    607611        for sublist in second_item:
  • tests/regressiontests/defaultfilters/tests.py

     
    347347>>> unordered_list(['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']])
    348348u'\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>'
    349349
     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])
     359u'\t<li>ulitem-a</li>\n\t<li>ulitem-b</li>'
     360
    350361# Old format for unordered lists should still work
    351362>>> unordered_list([u'item 1', []])
    352363u'\t<li>item 1</li>'
Back to Top