I am trying to replicate the example in the web2py cookbook on Creating a 
navigation bar (page 89) i.e. a menu based on rows in database table
So I have build the model

db.define_table('navbar',
Field("title", type='string',length='25', notnull=True, required=True),
Field("url", type='string', length='25', requires=IS_EMPTY_OR(IS_URL())),
Field("con", label="Controller"),
Field("fun", label="Function"),
Field("arg",label="Arguments"),
Field("sor", type='integer'),
Field("parent_id", "reference navbar"),
format="%(title)s",
)

I have build the controller

def get_sub_menus(parent_id, default_c=None, default_f=None):
    children = db(db.navbar.parent_id==parent_id)
    for menu_entry in children.select(orderby=db.navbar.sor):
        c = menu_entry.con or default_c
        f = menu_entry.fun or default_f
        s = (request.controller==c and request.function==f and (request.args 
and request.args==menu_entry.arg or True))
        yield (T(menu_entry.title), s, menu_entry.url or URL(c, f, args=
menu_entry.arg), get_sub_menus(menu_entry.id, c, f))

and added some rows to the navbar table and start the menu

response.menu = get_sub_menus(parent_id=None)

I get the error message

<type 'exceptions.TypeError'> 'generator' object has no attribute 
'__getitem__'

I read some explanation on iterators and generators but I don't know how to 
solve this.



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to