I was working on a set menu from the database. It's simple and it can be
useful.
The model is simple, and has a condition to evaluate options when
generating the menu items.
The evaluation was done using the function 'eval'.
Attach model.
To manage SQLFORM.grid use or what you like
db.define_table('menu',
Field('posicion',type='integer'),
Field('titulo',type='string'),
Field('controlador',type='string'),
Field('funcion',type='string'),
Field('padre'),
Field('condicion'),
)
db.menu.padre.requires = IS_IN_DB(db, db.menu.id,'%(titulo)s')
db.menu.padre.represent = lambda id,row: db.menu(id).titulo
db.menu.condicion.default = 'True'
response.title = settings.title
response.subtitle = settings.subtitle
response.meta.author = '%(author)s <%(author_email)s>' % settings
response.meta.keywords = settings.keywords
response.meta.description = settings.description
response.menu = [ ]
def add_item(nivel):
item = []
for itemmenu in db((db.menu.padre == nivel) & (db.menu.id >
1)).select(orderby=db.menu.posicion):
if eval(itemmenu.condicion):
item.append([itemmenu.titulo,None,URL(itemmenu.controlador,itemmenu.funcion),add_item(
itemmenu.id) ])
return item
if auth.is_logged_in():
response.menu = add_item(1)
On Thu, Apr 12, 2012 at 1:00 AM, Cliff <[email protected]> wrote:
> I have something like this working:
>
> sub_menu = []
> if (auth.user_id != None) and ((auth.has_membership(role = 'admin'))):
> sub_menu = [('Admin', False, URL('admin')), ]
> response.menu = [('Home', False, URL('home','default','index'), []),
> (SPAN('Price List',_style='color:yellow'), True,
> URL('pricelist','default','index'),
> [('Guideline', False, URL('pricelist','default','guideline')),
> ('Multiplier Tables', False,
> URL('pricelist','default','multitable')),
> ('Cut Charge Tables', False, URL('pricelist','default','cuttable')),
> (sub_menu),
> ])]
>
> On Wednesday, April 11, 2012 12:24:29 PM UTC-4, Omi Chiba wrote:
>>
>> The following menu works. It's add "Admin" menu next to "Price List" if
>> the user has role "admin". Now, I want to add the "Admin" menu as sub-menu
>> of "Price List" where it's right after the "Cut Charge Tables". How can I
>> do this ?
>>
>> response.menu = [('Home', False, URL('home','default','index'), []),
>> (SPAN('Price List',_style='color:yellow'), True,
>> URL('pricelist','default','**index'),
>> [('Guideline', False, URL('pricelist','default','**guideline')),
>> ('Multiplier Tables', False, URL('pricelist','default','**
>> multitable')),
>> ('Cut Charge Tables', False, URL('pricelist','default','**
>> cuttable')),
>> ])]
>>
>> if (auth.user_id != None) and ((auth.has_membership(role = 'admin'))):
>> response.menu += [('Admin', False, URL('admin')), ]
>>
>