(newbie to both web2py and python - please be gentle) 

I am trying to use two menu selection items to control a view and I need 
guidance on the general strategy one should use. Intuitively (to me) this 
seems like it should be easy, but I have made various attempts, all of 
which fail in different ways. So, I assume I am approaching this in the 
wrong way. I would like one selection to set something that controls the 
type of the charts that will be displayed, and a second to control the 
actual content of the charts (country).  I thought I might do this by 
simply replacing the URL() in response.menu with a call to my own function 
that sets a global variable then calls the URL helper, but I am not having 
any luck.  I can get the controller and view to work with hard coded global 
variables, so I think the problem is in menu.py (but could be missing the 
big picture). The  relevant part of menu.py is 

ChartType = 'Recent' 
Country='US' 

def setChartType(x): 
   global ChartType 
   ChartType=x 
   URL('default', 'Country',) 
   return() 

def getChartType(): 
   return(ChartType) 

def setCountry(x): 
   global Country 
   Country=x 
   return(URL('default', 'Country')) 

def getCountry(): 
   return(Country) 

response.menu = [ 
    (I('xxx'), False, URL('default','index'), []) 
    ] 

def _(): 
    app = request.application 
    ctr = request.controller 
    response.menu+=[ 
        (SPAN('View',_style='color:yellow'),False, None, [ 
                 (T('by Country'),False,None, [ 
                        (T('Canada'),False, setCountry('Canada'),), 
                        (T('US'),False, setCountry('US'),), 
                         ]), 
                ]), 
        (SPAN('Chart Type',_style='color:yellow'),False, None, [ 
               (T('Recent'),False, setChartType('Recent'),), 
               (T('Historical'),False,setChartType('Historical'),), 
                ]), 
     ] 
_() 

Will this strategy work with small tweaks, or am I missing something big? 

Related, I can see that I might be able to do this using AJAX. There seems 
to be some overlap between things that could be done directly within the 
web2py/python framework, and things that might be done with AJAX. What are 
the main reasons one would usually choose one or the other? 

Thanks, 
Paul 

-- 

--- 
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.


Reply via email to