def load_ancestors(pages):
 pages_by_id = dict(((page.pk, page) for page in pages))
 pages_list = list(pages)
 missing = list(pages)
 while missing:
  page = missing.pop()
  page.ancestors_descending = []
  page._cached_descendants = []
  if (page.parent_id and (page.parent_id not in pages_by_id)):
   pages_list.append(page.parent)
   pages_by_id[page.parent_id] = page.parent
   missing.append(page.parent)
 pages_list.sort(key=(lambda page: page.path))
 for page in pages_list:
  if page.parent_id:
   parent = pages_by_id[page.parent_id]
   page.ancestors_descending = (parent.ancestors_descending + [parent])
   for ancestor in page.ancestors_descending:
    ancestor._cached_descendants.append(page)
  else:
   page.ancestors_descending = []
  page.ancestors_ascending = list(reversed(page.ancestors_descending))
 return pages_list

def load_ancestors ( pages ) : pages_by_id = dict ( ( ( page . pk , page ) for page in pages ) ) pages_list = list ( pages ) missing = list ( pages ) while missing : page = missing . pop ( ) page . ancestors_descending = [ ] page . _cached_descendants = [ ] if ( page . parent_id and ( page . parent_id not in pages_by_id ) ) : pages_list . append ( page . parent ) pages_by_id [ page . parent_id ] = page . parent missing . append ( page . parent ) pages_list . sort ( key = ( lambda page : page . path ) ) for page in pages_list : if page . parent_id : parent = pages_by_id [ page . parent_id ] page . ancestors_descending = ( parent . ancestors_descending + [ parent ] ) for ancestor in page . ancestors_descending : ancestor . _cached_descendants . append ( page ) else : page . ancestors_descending = [ ] page . ancestors_ascending = list ( reversed ( page . ancestors_descending ) ) return pages_list
loads the ancestors .