Package s3 :: Module s3hierarchy :: Class S3Hierarchy
[frames] | no frames]

Class S3Hierarchy

source code

object --+
         |
        S3Hierarchy

Class representing an object hierarchy

Instance Methods
 
__init__(self, tablename=None, hierarchy=None, represent=None, filter=None, leafonly=True)
Constructor
source code
 
theset(self)
The raw nodes dict like:
source code
 
flags(self)
Dict of status flags
source code
 
config(self)
Hierarchy configuration of the target table
source code
 
nodes(self)
The nodes in the subset
source code
 
roots(self)
The IDs of the root nodes in the subset
source code
 
pkey(self)
The parent key
source code
 
fkey(self)
The foreign key referencing the parent key
source code
 
link(self)
The name of the link table containing the foreign key, or None if the foreign key is in the hierarchical table itself
source code
 
lkey(self)
The key in the link table referencing the child
source code
 
left(self)
The left join with the link table containing the foreign key
source code
 
ckey(self)
The category field
source code
 
load(self)
Try loading the hierarchy from s3_hierarchy
source code
 
save(self)
Save this hierarchy in s3_hierarchy
source code
 
read(self)
Rebuild this hierarchy from the target table
source code
 
preprocess_create_node(self, r, parent_id)
Pre-process a CRUD request to create a new node
source code
 
postprocess_create_node(self, link, node)
Create a link table entry for a new node
source code
 
delete(self, node_ids, cascade=False)
Recursive deletion of hierarchy branches
source code
 
add(self, node_id, parent_id=None, category=None)
Add a new node to the hierarchy
source code
 
remove(self, node_id)
Remove a node from the hierarchy
source code
 
category(self, node_id)
Get the category of a node
source code
 
parent(self, node_id, classify=False)
Get the parent node of a node
source code
 
children(self, node_id, category=DEFAULT, classify=False)
Get child nodes of a node
source code
 
path(self, node_id, category=DEFAULT, classify=False)
Return the ancestor path of a node
source code
 
root(self, node_id, category=DEFAULT, classify=False)
Get the root node for a node.
source code
 
depth(self, node_id, level=0)
Determine the depth of a hierarchy
source code
 
siblings(self, node_id, category=DEFAULT, classify=False, inclusive=False)
Get the sibling nodes of a node.
source code
 
findall(self, node_id, category=DEFAULT, classify=False, inclusive=False)
Find descendant nodes of a node
source code
 
label(self, node_id, represent=None)
Get a label for a node
source code
 
json(self, root=None, represent=None, max_depth=None)
Represent the hierarchy as JSON-serializable dict
source code
 
html(self, widget_id, root=None, represent=None, hidden=True, none=None, _class=None)
Render this hierarchy as nested unsorted list
source code
 
export_node(self, node_id, prefix="_hierarchy", depth=None, level=0, path=None, hcol=None, columns=None, data=None, node_list=None)
Export the hierarchy beneath a node
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
 
dirty(cls, tablename)
Mark this hierarchy as dirty.
source code
Properties

Inherited from object: __class__

Method Details

__init__(self, tablename=None, hierarchy=None, represent=None, filter=None, leafonly=True)
(Constructor)

source code 

Constructor

Parameters:
  • tablename - the tablename
  • hierarchy - the hierarchy setting for the table (replaces the current setting)
  • represent - a representation method for the node IDs
  • filter - additional filter query for the table to select the relevant subset
  • leafonly - filter strictly for leaf nodes
Overrides: object.__init__

theset(self)

source code 

The raw nodes dict like:

    {<node_id>: {"p": <parent_id>,
                 "c": <category>,
                 "s": set(child nodes)
    }}

Decorators:
  • @property

flags(self)

source code 

Dict of status flags

Decorators:
  • @property

config(self)

source code 

Hierarchy configuration of the target table

Decorators:
  • @property

nodes(self)

source code 

The nodes in the subset

Decorators:
  • @property

roots(self)

source code 

The IDs of the root nodes in the subset

Decorators:
  • @property

pkey(self)

source code 

The parent key

Decorators:
  • @property

fkey(self)

source code 

The foreign key referencing the parent key

Decorators:
  • @property

link(self)

source code 

The name of the link table containing the foreign key, or None if the foreign key is in the hierarchical table itself

Decorators:
  • @property

lkey(self)

source code 

The key in the link table referencing the child

Decorators:
  • @property

left(self)

source code 

The left join with the link table containing the foreign key

Decorators:
  • @property

ckey(self)

source code 

The category field

Decorators:
  • @property

load(self)

source code 

Try loading the hierarchy from s3_hierarchy

save(self)

source code 

Save this hierarchy in s3_hierarchy

dirty(cls, tablename)
Class Method

source code 

Mark this hierarchy as dirty. To be called when the target table gets updated (can be called repeatedly).

Parameters:
  • tablename - the tablename

read(self)

source code 

Rebuild this hierarchy from the target table

preprocess_create_node(self, r, parent_id)

source code 

Pre-process a CRUD request to create a new node

Parameters:
  • r - the request
  • table - the hierarchical table
  • parent_id - the parent ID

postprocess_create_node(self, link, node)

source code 

Create a link table entry for a new node

Parameters:
  • link - the link information (as returned from preprocess_create_node)
  • node - the new node

delete(self, node_ids, cascade=False)

source code 

Recursive deletion of hierarchy branches

Parameters:
  • node_ids - the parent node IDs of the branches to be deleted
  • cascade - cascade call, do not commit (internal use)
Returns:
number of deleted nodes, or None if cascade failed

add(self, node_id, parent_id=None, category=None)

source code 

Add a new node to the hierarchy

Parameters:
  • node_id - the node ID
  • parent_id - the parent node ID
  • category - the category

remove(self, node_id)

source code 

Remove a node from the hierarchy

Parameters:
  • node_id - the node ID

category(self, node_id)

source code 

Get the category of a node

Parameters:
  • node_id - the node ID
Returns:
the node category

parent(self, node_id, classify=False)

source code 

Get the parent node of a node

Parameters:
  • node_id - the node ID
  • classify - return the root node as tuple (id, category) instead of just id
Returns:
the root node ID (or tuple (id, category), respectively)

children(self, node_id, category=DEFAULT, classify=False)

source code 

Get child nodes of a node

Parameters:
  • node_id - the node ID
  • category - return only children of this category
  • classify - return each node as tuple (id, category) instead of just ids
Returns:
the child nodes as Python set

path(self, node_id, category=DEFAULT, classify=False)

source code 

Return the ancestor path of a node

Parameters:
  • node_id - the node ID
  • category - start with this category rather than with root
  • classify - return each node as tuple (id, category) instead of just ids
Returns:
the path as list, starting at the root node

root(self, node_id, category=DEFAULT, classify=False)

source code 

Get the root node for a node. Returns the node if it is the root node itself.

Parameters:
  • node_id - the node ID
  • category - find the closest node of this category rather than the absolute root
  • classify - return the root node as tuple (id, category) instead of just id
Returns:
the root node ID (or tuple (id, category), respectively)

depth(self, node_id, level=0)

source code 

Determine the depth of a hierarchy

Parameters:
  • node_id - the start node (default to all root nodes)

siblings(self, node_id, category=DEFAULT, classify=False, inclusive=False)

source code 

Get the sibling nodes of a node. If the node is a root node, this method returns all root nodes.

Parameters:
  • node_id - the node ID
  • category - return only nodes of this category
  • classify - return each node as tuple (id, category) instead of just id
  • inclusive - include the start node
  • return - a set of node IDs (or tuples (id, category), respectively)

findall(self, node_id, category=DEFAULT, classify=False, inclusive=False)

source code 

Find descendant nodes of a node

Parameters:
  • node_id - the node ID (can be an iterable of node IDs)
  • category - find nodes of this category
  • classify - return each node as tuple (id, category) instead of just ids
  • inclusive - include the start node(s) if they match
Returns:
a set of node IDs (or tuples (id, category), respectively)

label(self, node_id, represent=None)

source code 

Get a label for a node

Parameters:
  • node_id - the node ID
  • represent - the node ID representation method

json(self, root=None, represent=None, max_depth=None)

source code 

Represent the hierarchy as JSON-serializable dict

Parameters:
  • root - the root node ID (or array of root node IDs)
  • represent - the representation method
  • max_depth - maximum recursion depth
Returns:
the hierarchy as dict: {node_id: [label, category, subnodes], ...}

html(self, widget_id, root=None, represent=None, hidden=True, none=None, _class=None)

source code 

Render this hierarchy as nested unsorted list

Parameters:
  • widget_id - a unique ID for the HTML widget
  • root - node ID of the start node (defaults to all available root nodes)
  • represent - the representation method for the node IDs
  • hidden - render with style display:none
  • _class - the HTML class for the outermost list
Returns:
the list (UL)

export_node(self, node_id, prefix="_hierarchy", depth=None, level=0, path=None, hcol=None, columns=None, data=None, node_list=None)

source code 

Export the hierarchy beneath a node

Parameters:
  • node_id - the root node
  • prefix - prefix for the hierarchy column in the output
  • depth - the maximum depth to export
  • level - the current recursion level (internal)
  • path - the path dict for this node (internal)
  • hcol - the hierarchy column in the input data
  • columns - the list of columns to export
  • data - the input data dict {node_id: row}
  • node_list - the output data list (will be appended to)
Returns:
the output data list

To Do: pass the input data as list and retain the original order when recursing into child nodes?