I also tried implementing menus based on a DB table so that I could display 
options which related to user permissions.  However,  in the end it became 
rather complicated and I decided it wasn't worth the effort and I went back 
to some kind of simple text representation.

For simplicity,  I really like the plugin_wiki menu idea and would 
recommend that you also consider that method.  I found it is relatively 
easy to have a few different text menus which may be selected for each 
different user group.  When I thought about it,  I only need three menus so 
this is really easy to maintain.  The menus can still be kept in the DB.

Sorry that this doesn't directly answer your question but it may have given 
you another idea  :)
Regards,  David



On Tuesday, July 10, 2012 11:22:06 AM UTC+1, Alan wrote:
>
> hi,
>
> wonder if i could have some input please on where im going wrong, spent a 
> few hours getting my head round this, but can't seem to get it right.
>
> taking inspiration from this: 
> http://wizardinternetsolutions.com/web-database-design/single-query-dynamic-multi-level-menu/
>
> I am trying to build up a array of elements that replicates the static 
> method in menus.py:
>
> response.ttt = db((db.page.showinmenu==1)&(db.page.active==1)).select(db.
> page.id, db.page.menutext, db.page.pageurl, db.page.parent, orderby=db.
> page.parent|db.page.sort|db.page.menutext)
> response.tttmenu = [[],dict()]
> for subpage in response.ttt:
>     response.tttmenu[0].append({subpage.id: [subpage.menutext, subpage.
> pageurl, subpage.parent]})
>     if subpage.parent in response.tttmenu[1]:
>         response.tttmenu[1][subpage.parent].append(subpage.id)
>     else:
>         response.tttmenu[1][subpage.parent] = [subpage.id]
>
> def buildmenu(parent, menu):
>     html = ''
>     if menu[1][parent]:
>         html += '<ul>'
>         for itemid in menu[1][parent]:
>             if itemid in menu[1]:
>                 html += str(menu[0][itemid])
>                 #html += '<li>'+str(menu[0][itemid])
>                 #html += buildmenu(menu[0][itemid][1][0], menu)
>                 html += '</li>'
>             else:
>                 #html += '<li>'+str(menu[0][itemid])+'</li>'
>                 html += 'Badgers'
>     html += '</ul>'
>     return html
>
> response.tttnewmenu = buildmenu(0, response.tttmenu)
>
> so the first bit sticks the query results into a array, the page elements 
> into array index 0 as arrays and then the list of parents into array index 
> 1 as dictionaries for each element that has parents.
> tttmenu outputs:
>
> [[{1: ['Home', 'home', 0]}, {3: ['page3', 'page3', 0]}, {2: ['page2', 
> 'page2', 1]}], {0: [1, 3], 1: [2]}]
>
> which seems right compared to the link above, but i just can't get the 
> second bit right.
>
> that is supposed to query through the parents dictionary keys and for each 
> array element inside the key, check if it is a parent and if so go through 
> the function again, so that it puts order into the output to the same 
> standard as the static response.menu example. the intention is to replace 
> all the html in the function and turn it into an array, but wanted to walk 
> through and get the code right.
> The main problem i've got is calling the page array element 0 (the page 
> title) based on the dictionary key element that is being looped, just can't 
> get the syntax right no matter how much i try.
>
> any help would be greatly appreciated, even if you just tell me im doing 
> it wrong and should look at something else.
>
> was looking at doing things this way to first prevent too many database 
> queries on menu building and also to save having an additional table in the 
> database dedicated to the menu.
>
> all part of a cms im making and intend to release once it's any good.
>
> Thank you,
>
> Alan
>
>
>

Reply via email to