'Dumps a tree branch to a python data structure.'

@classmethod
def dump_bulk_tree(cls, parent=None, keep_ids=True):

    qset = cls._get_serializable_model().get_tree(parent)
    (ret, lnk) = ([], {})
    for pyobj in qset:
        serobj = serializers.serialize('python', [pyobj])[0]
        fields = serobj['fields']
        depth = fields['depth']
        fields['text'] = fields['name']
        fields['href'] = fields['slug']
        del fields['name']
        del fields['slug']
        del fields['path']
        del fields['numchild']
        del fields['depth']
        if ('id' in fields):
            del fields['id']
        newobj = {}
        for field in fields:
            newobj[field] = fields[field]
        if keep_ids:
            newobj['id'] = serobj['pk']
        if (((not parent) and (depth == 1)) or (parent and (depth == parent.depth))):
            ret.append(newobj)
        else:
            parentobj = pyobj.get_parent()
            parentser = lnk[parentobj.pk]
            if ('nodes' not in parentser):
                parentser['nodes'] = []
            parentser['nodes'].append(newobj)
        lnk[pyobj.pk] = newobj
    return ret
