My code above seems to only be lacking the proper embedded if conditional statement. I am able to output the same info I need without repeating it like in this example:
rows = db(db.store_categories).select() for menucatchoice in rows: if menucatchoice['subcategory'] == '': print "Main - %s " % menucatchoice['maincategory'] if menucatchoice['subcategory']: print "SubCategory -- %s " % menucatchoice['subcategory'] Which prints out: Main - Animals SubCategory -- Dogs SubCategory -- Cats Why can't I get it to go like that with my code above? My code is much smaller and actually works for seeing what happens. With the suggested code that isn't working I'm unable to see anything and therefore unable to even debug it since it crashes immediately. Also I was wondering if there was any actual way to see what MENU helper actually sees, and not just using the shell. For example when you click on the response in the ticket it shows the menu but doesn't show the actual received output. When I view that in the shell and make adjustments such as adding/subtracting []] or similar it is difficult to deduce what MENU has determined as a link, false, or whatever. I have also tried other variations such as: menu.py response.menu = [T('Catalog'), False, '',[]] maininfo=db(db.store_categories.subcategory=='').select(db.store_categories.maincategory) for maincat in maininfo: response.menu[-1]+=([(T(maincat.maincategory)), False, 'link']) for subcat in db(db.store_categories.subcategory!='').select(db.store_categories.subcategory): response.menu[-1]+=([[(T(subcat.subcategory)), False, 'link',]]) Which gets me this in the shell: [<lazyT 'Catalog'>, False, '', [<lazyT 'Animals'>, False, 'link', [<lazyT 'Dogs'>, False, 'link'], [<lazyT 'Cats'>, False, 'link']]] And for the astute observer you can see the correct way (i statically created and works): [(<lazyT 'Catalog'>, False, '', [(<lazyT 'Animals'>, False, '/beta/default/Animals', [(<lazyT 'Dogs'>, False, '/beta/default/Dogs'), (<lazyT 'Cats'>, False, '/beta/default/Cats')])])] You can see the slight differences so obviously I am very close. For further clarity for myself and anyone else reading this(it has become clear others have tried this extensively), you can see I need to have one less bracket (if I'm correct). I say this because in the "working/correct" version you can clearly see that the last entry "(<lazyT 'Cats'>, False, '/beta/default/Cats')])])]" is missing the bracket that my generated one has "[<lazyT 'Cats'>, False, 'link']]]". I realize the "()" aren't the same however I noticed that in the shell unless the structure shows correctly as outlined above that it does not work regardless of the "()". You can also see that the bracket only encompasses the subcategories. So I'm wondering how I can get that one bracket out of here (again if I'm correct about the format). I appreciate all the code samples but, it appears I'm doing something trivially wrong which doesn't suffice replacing the whole thing for (in my opinion due to one bracket being off). On Monday, January 20, 2014 2:33:50 PM UTC-6, web2pygroup wrote: > > > Hi all, > > I have been trying for a little over 2 weeks to figure this out... > > I'm trying to generate a menu that drops down, I have been able to > statically create it by overwriting sample app that has the same drop down > menu like the web2py.com site. > > I have this in my db.py: > db.define_table('store_catalog', > Field('maincategory', 'string'), > Field('subcategory', 'string'), > Field('description', 'text')) > > > in my menu.py I have gotten this so far: > response.menu=[] > response.menu.append([T('Catalog'), False, '', > [(T('%s' % menucatchoice['maincategory']), False, 'link', > [(T('%s' % menucatchoice['subcategory']), False, > 'link'),]) for menucatchoice in rows ] ]) > > It gets me a drop down menu except that for each subcategory it repeats > adding it to the main category. Let's say there is only 1 main category and > 2 subs that go after that > Catalog (this just shows with the caret next to it as intended) > MainCategory > Sub > Sub > What I have does put the "Catalog" for the first but, what I get is: > MainCategory > (blank) > MainCategory(don't want this it's being repeated) > Subcategory > MainCategory(and this one is also a repeat) > Subcategory > > I have tried to break out the response.menu with so many different > .appends it's not funny. I have also tried adding the "[-1]". This was > the closest I have gotten to what I want it to look like. I'm at an > absolute loss on this, any and all help would be greatly appreciated. > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.