Utilities for working with lists of model instances which represent trees.
From http://www.wordaligned.org/articles/zippy-triples-served-with-python
Creates an iterator which returns (previous, current, next) triples, with None filling in when there is no previous or next available.
Given a list of tree items, iterates over the list, generating two-tuples of the current tree item and a dict containing information about the tree structure around the item, with the following keys:
- 'new_level'
- True if the current item is the start of a new level in the tree, False otherwise.
- 'closed_levels'
- A list of levels which end after the current item. This will be an empty list if the next item is at the same level as the current item.
If ancestors is True, the following key will also be available:
- 'ancestors'
A list of unicode representations of the ancestors of the current node, in descending order (root node first, immediate parent last).
For example: given the sample tree below, the contents of the list which would be available under the 'ancestors' key are given on the right:
Books -> [] Sci-fi -> [u'Books'] Dystopian Futures -> [u'Books', u'Sci-fi']
Creates a drilldown tree for the given node. A drilldown tree consists of a node’s ancestors, itself and its immediate children, all in tree order.
Optional arguments may be given to specify a Model class which is related to the node’s class, for the purpose of adding related item counts to the node’s children: