Node

class business_logic.models.Node(*args, **kwargs)

Derived from treebeard.NS_Node. Holds structure of syntax tree. All objects are linked using the django contenttypes framework. Interprets code using the business_logic.models.Node.interpret() method. Can acts as parent of code block if not contains content_object. Can contains comment.

static ensure_content_object_saved(**kwargs)

Saves content_object if needed.

classmethod add_root(**kwargs)

Adds a root node to the tree. Saves content_objects if needed. :param **kwargs: kwargs for business_logic.models.Node constructor

Returns:created root node
Return type:business_logic.models.Node
add_child(**kwargs)

Adds a child to the node. Saves content_objects if needed.

Parameters:**kwargs – kwargs for business_logic.models.Node constructor
Returns:created node
Return type:business_logic.models.Node
delete()

Removes a node and all it’s descendants, and content_objects if needed.

clone()

Creates a clone of entire tree starting from self

Returns:root node of cloned tree
Return type:business_logic.models.Node
interpret(ctx)

Interprets the held code.

Parameters:ctx (business_logic.models.Context) – execution context
Returns:interpreted value
pprint()

Prints entire tree starting from self to stdout.

Utility function for development purposes.

class business_logic.models.NodeCache

Creates cache with preloaded content objects for entire tree on first call of get_children().

Uses 1 + n SQL queries, where n is count of used content types.

get_children(node)

Returns cached child nodes

Parameters:node (business_logic.models.Node) – parent node
Returns:list of business_logic.models.Node
class business_logic.models.NodeCacheHolder

Implements get_children() function using business_logic.models.NodeCache

get_children(node)

Returns cached child nodes

Parameters:node (business_logic.models.Node) – parent node
Returns:list of business_logic.models.Node
class business_logic.models.NodeVisitor

Utility class for tree traversal.

Derived class should implement the business_logic.models.NodeVisitor.visit() method. Traversal is made by executing business_logic.models.NodeVisitor.preorder() or business_logic.models.NodeVisitor.postorder() method.

Examples

visit(node, *args, **kwargs)

Main method which should be realised in derived classes

Parameters:
preorder(node, *args, **kwargs)

Tree traversal from top to bottom.

Parameters:
postorder(node, *args, **kwargs)

Tree traversal from bottom to top.

Parameters: