Here is a function which may be of interest. I have included some test input data. The data is not really nested-list because it doesn't have 'lft' and 'rgt' fields. Rather this assumes that you are using a simple parent_id field to build a list suitable for superfish. If you come up with anything interesting, please let me know.
def test_html_nodes(nodes,link_to_function='area'): if not nodes: nodes = [ { 'id':1, 'parent_id':None, 'name':'a' }, { 'id':2, 'parent_id':None, 'name':'b' }, { 'id':3, 'parent_id':2, 'name':'c' }, { 'id':4, 'parent_id':2, 'name':'d' }, { 'id':5, 'parent_id':4, 'name':'e' }, { 'id':6, 'parent_id':None, 'name':'f' } ] global output output = '' global count count = 0 def build_node(node): global output li_id = ' id="%s"' % node['id'] output += '<li%s>'%li_id + \ str(A(node['name'],_href=URL(link_to_function,args=[node[ 'id']]))) build_nodes(node['id']) output += '</li>' def build_nodes(node_parent_id): global output global count count += 1 subnodes = [node for node in nodes if node['parent_id'] ==node_parent_id ] if len(subnodes) > 0 : cl = ' class="sf-menu sf-vertical sf-js-enabled sf-shadow"' ifcount ==1 else '' output += '<ul%s>' % cl [build_node(subnode) for subnode in subnodes] output += '</ul>' build_nodes(None) # Pass in None as a parent id to start with top level nodes return output