thank you Massimo, I wanted to generate valid html and I was not able
to embed, for subcategories, <ul> inside <li> directly using the
web2py html helpers.
It won me this round (time presion), but I build it just as html and
got it working as follow:
def catree():
# Identificando a las categorías raíces o de primer nivel
supercategorias =
db(db.t_categoria.supercategoria==None).select(db.t_categoria.id,db.t_categoria.nombre)
htmlmenu = '<ul id="catree">'
# Generando 1er nivel del árbol de categorías
for supercat in supercategorias:
htmlmenu+='<li class="catree_1">'+supercat.nombre
# Identificando categorías de 2do nivel
cats=db(db.t_categoria.supercategoria==supercat.id).select(db.t_categoria.nombre,db.t_categoria.id)
if cats:
htmlmenu+='<ul>'
# Generando 2do nivel del árbol de categorías
for cat in cats:
htmlmenu+=str(LI(A(cat.nombre,
_href=URL(f=articulo,args=cat.id),cid="caja"), _class="catree_2"))
htmlmenu+='</ul>'
htmlmenu+='</li>'
htmlmenu+='</ul>'
return dict(htmlmenu=XML(htmlmenu))
I love web2py as my only framework, thank you Massimo for build it and
all the community for keep improving it :)
2011/2/14 Massimo Di Pierro <[email protected]>:
> This
>
> def catree2():
> supercategorias =
> db(db.t_categoria.supercategoria==None).select(db.t_categoria.id,db.t_categ
> oria.nombre)
> catree = []
> for supercat in supercategorias:
> catree.append([supercat.nombre,False,'link'])
> cats =
> db(db.t_categoria.supercategoria==supercat.id).select(db.t_categoria.nombre
> ,db.t_categoria.id)
> for cat in cats:
> catree[-1].append([cat.nombre,False,'link'])
>
> should be
>
> def catree2():
> supercategorias =
> db(db.t_categoria.supercategoria==None).select(db.t_categoria.id,db.t_categ
> oria.nombre)
> catree = []
> for supercat in supercategorias:
> catree.append([supercat.nombre,False,'link',[]])
> cats =
> db(db.t_categoria.supercategoria==supercat.id).select(db.t_categoria.nombre
> ,db.t_categoria.id)
> for cat in cats:
> catree[-1].append([cat.nombre,False,'link'])
>
> also URL('#') should just be '#'.
>
>
>
> On Feb 14, 7:19 am, danto <[email protected]> wrote:
>> Hi, I attached the whole ticket.
>>
>> thanks in advance for any help.
>>
>> the controller remains as:
>>
>> CONTROLLER:
>> =======================
>> def catree2():
>> supercategorias =
>> db(db.t_categoria.supercategoria==None).select(db.t_categoria.id,db.t_categ
>> oria.nombre)
>>
>> catree = []
>>
>> for supercat in supercategorias:
>> catree.append([supercat.nombre,False,'link'])
>> cats =
>> db(db.t_categoria.supercategoria==supercat.id).select(db.t_categoria.nombre
>> ,db.t_categoria.id)
>> for cat in cats:
>> catree[-1].append([cat.nombre,False,'link'])
>>
>> """
>> for supercats in supercategorias:
>> #me.append(LI(A(supercats.nombre, _href="#"),_class="catree_1"))
>> response.menu+=[(supercats.nombre,False,URL('#'))]
>>
>> # Identtificando categorías de 2do nivel
>>
>> cats=db(db.t_categoria.supercategoria==supercats.id).select(db.t_categoria.
>> nombre,db.t_categoria.id)
>>
>> for cat in cats:
>> response.menu.append([cat.nombre,False,URL('#')])
>> """
>>
>> return dict(catree=catree)
>> #return locals()