Hello,

I'm facing I guess a well known programming problem. It is not really
related to web2by, but since I'm using web2py I hope somebody here can
help.

Here is my controller :

def global_view():
    parents = db(~(db.t_article.id==db.t_list.f_article)).select()
    tree={}
    for parent in parents:
        tree[parent.t_article.id]={}
        sublevel=db(parent.t_article.id==db.t_list.f_parent).select()
        for son in sublevel:
            tree[parent.t_article.id][son.f_article]=son.f_article
            tree[parent.t_article.id][son.f_article]={}
            sublevel2=db(son.f_article==db.t_list.f_parent).select()
            for son2 in sublevel2:
                tree[parent.t_article.id][son.f_article]
[son2.f_article]=son2.f_article
                tree[parent.t_article.id][son.f_article][son2.f_article]={}
    return dict(tree=tree)

So in fact I'd like to go on for son3, son4, based on the same model
as sublevel2... until sublevelx=None.
I guess I should use some kind of recursive or loop function.
I've read different things using right and left variable for
hierarchical tree, but it seems to me that it is possible to build a
loop in my controller without modifying my model.

Hope I do not disturb this groupes with this kind of question.

Reply via email to