Take a look to this code.

#list slices who own
def my_slices():

    user_id = session.auth.user.id
    slices = db(db.slices.user_id == user_id).select(db.slices.id,
                                                     db.slices.title)
    myslices = [
                (T('Add slice'), False, A(T('Add slice'), \
                                          _title=T("Upload a slice"), \
                                          _href=URL('default','upload')))

                ]
    if slices:
        for slice in slices:
            myslices.append(('%s'%slice.title, False, A('%s'%slice.title, \
                                          _title=T("Edit a slice"), \
                                          _href=URL('default','edit',args=[
slice.id]))))


    return myslices


response.menu = [
    (T('My slices'), False, A(T('My slices'),_href='javascript: void(0);'),
     my_slices())
    ]

2011/3/21 annet <annet.verm...@gmail.com>

> In db.py I defined the following table:
>
> db.define_table('cardfunction',
>
> Field('company_id',db.company,default='',notnull=True,unique=True),
>    Field('home',type='boolean',default=True),
>    Field('logo',type='boolean',default=False),
>    Field('tagline',type='boolean',default=False),
>    Field('image',type='boolean',default=False),
>    Field('css',type='boolean',default=False),
>    Field('customcss',type='boolean',default=False),
>    Field('keywords',type='boolean',default=False),
>    migrate=False)
>
> Based on this table I would like to generate a menu. In a controller I
> got the following code:
>
> if not session.id or session.id!=auth.user.bedrijf_id:
>    session.id=auth.user.bedrijf_id
>
> session.row=db(db.cardfunction.bedrijf_id==session.id
> ).select(db.cardfunction.ALL)
>    session.card_menu=[
>         ['Home',request.function=='index',URL(r=request,f='index')],
>        ['Logo',request.function=='logo',URL(r=request,f='logo')],
>        ...
>
> ['Keywords',request.function=='keywords',URL(r=request,f='keywords')]]
>
>
> In the view I would like to generate a menu, in which, if the
> session.row.field value is true a link is being rendered and if
> session.row.field is false a <h4></h4> element is being rendered. What
> I had in mind:
>
> <ul>
>  {{for _name,_active,_link in session.card_menu:}}
>    {{if session.row.home:}}
>      <li>
>        <a {{if _active:}} class="active" {{pass}}
> href="{{=_link}}">{{=_name}}</a>
>      </li>
>    {{else:}}
>      <li>
>        {{=_name}}
>      </li>
>    {{pass}}
>      ....
>  {{pass}}
> </ul>
>
> ... doesn't work. Besides, if session.row.home: seven times, once for
> every field isn't a very elegant solution either. I hope one of you
> can provide me with a solution.
>
> Kind regards,
>
> Annet.




-- 
Pablo Martín Mulone (mar...@tecnodoc.com.ar)
http://www.tecnodoc.com.ar/

My blog: http://martin.tecnodoc.com.ar
Expert4Solution Profile:
http://www.experts4solutions.com/e4s/default/expert/6

Reply via email to