def build_summary(layout, level=1):
 assert (level > 0)
 level -= 1
 summary = List(klass=u'summary')
 for child in layout.children:
  if (not isinstance(child, Section)):
   continue
  label = layout_title(child)
  if ((not label) and (not child.id)):
   continue
  if (not child.id):
   child.id = label.replace(' ', '-')
  node = Link((u'#' + child.id), label=(label or child.id))
  if (level and [n for n in child.children if isinstance(n, Section)]):
   node = Paragraph([node, build_summary(child, level)])
  summary.append(node)
 return summary

def build_summary ( layout , level = 1 ) : assert ( level > 0 ) level -= 1 summary = List ( klass = u'summary' ) for child in layout . children : if ( not isinstance ( child , Section ) ) : continue label = layout_title ( child ) if ( ( not label ) and ( not child . id ) ) : continue if ( not child . id ) : child . id = label . replace ( ' ' , '-' ) node = Link ( ( u'#' + child . id ) , label = ( label or child . id ) ) if ( level and [ n for n in child . children if isinstance ( n , Section ) ] ) : node = Paragraph ( [ node , build_summary ( child , level ) ] ) summary . append ( node ) return summary
make a summary for the report .