Niphlod, Thanks, I will try to be as specific as possible.
Currently, I have 2 menus, both are defined in the models directory, dashboardmenu.py has a list of nav menu items like home, about, etc. menu.py contains another nav list that looks like the jpg I posted. This is the one I need extra help with. These menus are specified in the layouts.html and display with no problems. In the menu.py I want to display along with the menu title, a variable that shows some data value, a total, for example. I want the total to come from a controller function, not from a model. I don't understand how to do this because every example for a menu I've seen todate shows a variable coming from a function in a model file or from a db object. I think what I want can be done using html helpers, but I need to see an example of this. in models/menu.py, response.menu = [ (CAT(T('Daily Production'),BR(),B(URL=('default','test2')),B('W'),BR(),'Today''s Peak', myresult, 'W'), False,[]), #get no value from test2, how to get value? ] this results in an error, name 'test2' is not defined Traceback (most recent call last): File "/Applications/v232web2py/gluon/restricted.py", line 212, in restricted exec ccode in environment File "/Applications/v232web2py/applications/enp4/models/menu.py", line 35, in <module> (CAT(T('Power Production'),BR(),B(test2),B('W'),BR(),A('Today''s Peak',_href=URL('default','index')), myresult, 'W'), False,[]), #nearly NameError: name 'test2' is not defined This is the main problem, I don't know how to make the test2 a global variable in controllers/default.py there is a function, def test2(): a = 26 b = 32 myval = a+b return myval I want the contents of test2 to show up in the menu above as a variable 'label' under the title Daily Production. How do I do that, please? I want to display the variable output of controller/default/test2 function as a label in the menu.py, using html helpers., in the index.html view. I've added this to index.html but it does not help, {{if 'test2' in globals():}} {{=test2}} {{pass}} Maybe it is not possible to do this? On Wednesday, May 29, 2013 8:48:24 AM UTC-5, Niphlod wrote: > > I really don't understand what are you missing. > Please post an example of what you want and an example on where you are > stuck. > > PS: if "thesomething" you want to print comes as a result from a function, > why is difficult to do > > def afunction(a, b): > return a + b > def yourcontroller(): > thesomething = afunction(4,5) > response.menu.append( > (thesomething, False, URL('bla bla')) > ) > return dict() > > > > Il giorno mercoledì 29 maggio 2013 15:33:10 UTC+2, greaneym ha scritto: >> >> Niphlod, >> I am reposting with more questions on menus. >> Thank you, your response did clear up some questions. >> >> I want to have a menu item that shows the current total value of a >> calculation, >> as well as a sparkline chart showing the values of a time series. >> >> From the web2py-users, it seems that the menu tuple can be modified, the >> first and third elements of the tuple can be nested helper lists and the >> boolean in the middle can be used to turn on/off menu items, or just left >> alone. The boolean is what you call the "active" element, I think. >> >> but I need to see more examples of nested helpers. In meantime more >> experimenting. >> Here is something closer to what I need using your suggestion of putting >> test1 into myresult, >> which only works if I put it in the model file above the menu. >> It's not styled yet, but it has values appearing in the menu. >> <see jpg> >> >> Can you please help me figure out how to put the variable in the menu >> when it's coming from a controller function instead like test1? That is >> where most of my functions are. >> >> models/menusample.py contains >> def test1(): >> a = 20 >> b = 30 >> myval = a+b >> return myval >> >> myresult = test1() >> >> response.menu = [ >> (CAT(T('Power Production'),BR(),B(myresult),B('W'),BR(),A('Today''s >> Peak',_href=URL('default','index')), myresult, 'W'), False,[]), #nearly >> (CAT(T('Daily >> Production'),BR(),B(URL=('default','test2')),B('W'),BR(),'Today''s Peak', >> myresult, 'W'), False,[]), #get no value from test2, how to get value? >> (T('Item 2'), False, URL('default','index'), []) >> ] >> >> >> controllers/defaults.py contains function test2, >> >> def test2(): >> a = 26 >> b = 32 >> myval = a+b >> #return dict(myval=myval) #use whichever return will work in menu >> return myval >> >> I want to display the output of test2 as a variable, label in the menu, >> and it comes from a controller, not a model. >> >> On Tuesday, May 28, 2013 5:47:39 PM UTC-5, Niphlod wrote: >>> >>> missed the "very detailed post". >>> what does it mean that you want help with menu comprehension using a >>> controller ? >>> The menu can be defined wherever you want. Having it defined in models >>> is just a shortcut to avoid having to redefine it over and over, because >>> usually the menu is "fixed". >>> That being said, response.menu is just a list of tuples, optionally >>> containing another list as the fourth argument. >>> The scaffolding app has a pretty extensive menu where you can see the >>> structure needed to generate the menu. >>> Basically each item is >>> >>> (text, active_or_not, html_helper, [childrens]) >>> >>> now, let's forget for a second about: >>> - active_or_not (it just decorates with an "active" class the element) >>> - html_helper (you can put whatever you want, but then you'd override >>> the text part) >>> usually the menu item is >>> (text, False, URL('bla', 'bla') , [childrens]) >>> >>> This creates an A() tag, that holds "text" as value, URL('bla', 'bla') >>> as link, and has submenus (one for each item listed in childrens) >>> >>> to sum up, to have a menu that basically is >>> - menu 1 >>> - menu 1.1 >>> - menu 1.2 >>> - menu2 >>> you'd have something like >>> response.menu = [ >>> ('menu 1', False, URL('bla', 'bla'), [ >>> ('menu 1.1', False, URL('bla', 'bla')), >>> ('menu 1.2', False, URL('bla', 'bla')) >>> ]), >>> ('menu 2', False, URL('bla', 'bla')) >>> ] >>> >>> From there on, it's basic list slicing and dicing with python. >>> let's say you'd like to "insert" a "menu 1.3" in your controller, so in >>> that particular page only, a menu 1.3 would be visible.... >>> you'd have to append the new element to the fourth element (the >>> [children] list) of the first menu. >>> Remembering that python lists are 0-indexed : >>> response.menu[0][3].append( >>> ('menu 1.3', False, URL('bla', 'bla')) >>> ) >>> And voilà . >>> >>> Clearer ? >>> >>> On Wednesday, May 29, 2013 12:04:27 AM UTC+2, greaneym wrote: >>>> >>>> I posted a very detailed explanation of my progress so far and what I >>>> needed further. I can see it in the web2py-group posting but maybe you >>>> cannot see it? I need further help with menu comprehension using a >>>> controller instead of a model file. I can post again if you can't see the >>>> request. thanks. >>>> >>>> >>>> On Tuesday, May 28, 2013 3:25:53 PM UTC-5, Niphlod wrote: >>>>> >>>>> >>>>> >>>>> On Tuesday, May 28, 2013 10:15:24 PM UTC+2, greaneym wrote: >>>>>> >>>>>> Thanks that was helpful and got me further but I need a bit more help. >>>>>> >>>>>> >>>>>> >>>>> on what ? >>>>> >>>> -- --- 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.