def unordered_list(value, autoescape=None):
 if autoescape:
  from google.appengine._internal.django.utils.html import conditional_escape
  escaper = conditional_escape
 else:
  escaper = (lambda x: x)
 def convert_old_style_list(list_):
  "\n        Converts old style lists to the new easier to understand format.\n\n        The old list format looked like:\n            ['Item 1', [['Item 1.1', []], ['Item 1.2', []]]\n\n        And it is converted to:\n            ['Item 1', ['Item 1.1', 'Item 1.2]]\n        "
  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:
   it = 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 _helper(list_, tabs=1):
  indent = (u' DCTB ' * tabs)
  output = []
  list_length = len(list_)
  i = 0
  while (i < list_length):
   title = list_[i]
   sublist = ''
   sublist_item = None
   if isinstance(title, (list, tuple)):
    sublist_item = title
    title = ''
   elif (i < (list_length - 1)):
    next_item = list_[(i + 1)]
    if (next_item and isinstance(next_item, (list, tuple))):
     sublist_item = next_item
     i += 1
   if sublist_item:
    sublist = _helper(sublist_item, (tabs + 1))
    sublist = ('\n%s<ul>\n%s\n%s</ul>\n%s' % (indent, sublist, indent, indent))
   output.append(('%s<li>%s%s</li>' % (indent, escaper(force_unicode(title)), sublist)))
   i += 1
  return '\n'.join(output)
 (value, converted) = convert_old_style_list(value)
 return mark_safe(_helper(value))

def unordered_list ( value , autoescape = None ) : if autoescape : from google . appengine . _internal . django . utils . html import conditional_escape escaper = conditional_escape else : escaper = ( lambda x : x ) def convert_old_style_list ( list_ ) : 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 : it = 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 _helper ( list_ , tabs = 1 ) : indent = ( u' DCTB ' * tabs ) output = [ ] list_length = len ( list_ ) i = 0 while ( i < list_length ) : title = list_ [ i ] sublist = '' sublist_item = None if isinstance ( title , ( list , tuple ) ) : sublist_item = title title = '' elif ( i < ( list_length - 1 ) ) : next_item = list_ [ ( i + 1 ) ] if ( next_item and isinstance ( next_item , ( list , tuple ) ) ) : sublist_item = next_item i += 1 if sublist_item : sublist = _helper ( sublist_item , ( tabs + 1 ) ) sublist = ( '\n%s<ul>\n%s\n%s</ul>\n%s' % ( indent , sublist , indent , indent ) ) output . append ( ( '%s<li>%s%s</li>' % ( indent , escaper ( force_unicode ( title ) ) , sublist ) ) ) i += 1 return '\n' . join ( output ) ( value , converted ) = convert_old_style_list ( value ) return mark_safe ( _helper ( value ) )
recursively takes a self-nested list and returns an html unordered list -- without opening and closing <ul> tags .