def write_node(Document, node, doc_type, label_id, version=None):
    to_save = []
    labels_seen = set()

    def add_node(node, parent=None):
        label_tuple = tuple(node['label'])
        labels_seen.add(label_tuple)
        node['parent'] = parent
        to_save.append(node)
        for child in node['children']:
            add_node(child, parent=node)
    add_node(node)
    DMDocuments(Document).bulk_put(to_save, doc_type, label_id, version)
def write_node(Document, node, doc_type, label_id, version=None):
    to_save = []
    labels_seen = set()

    def add_node(node, parent=None):
        label_tuple = tuple(node['label'])
        labels_seen.add(label_tuple)
        node['parent'] = parent
        to_save.append(node)
        for child in node['children']:
            add_node(child, parent=node)
    add_node(node)
    DMDocuments(Document).bulk_put(to_save, doc_type, label_id, version)