Welcome to Python and web2py! There are two ways of looking at this issue.
1) "Model" refers to execution model upon which the controller is run and view is rendered. In this view, it is entirely acceptable to put these application-global things in a model file. 2) "Model" refers to data model. In this view, anything other than data descriptions contained in a model file is a violation of MVC. This is the view of MVC purists. I hold view #2. However, for those of us who hold view #2, web2py offers no easy way to have application-wide settings without violating our MVC convictions. I have reconciled my convictions by creating a separate "model" file called "settings.py" placed all my execution model stuff in that. Thereby sort of maintaining my view of MVC separation and still having easy access to application-wide settings. I sacrifice a white lamb to the MVC god every month until there is a better solution. =) -tim hcvst wrote: > Hi, > > thanks for the new release and all the effort you put in. Even if I am > new to web2py and not a seasoned Python programmer yet, the release > notes sound very promising and I look forward to experimenting > further. > > My question: > > Model files seem such a convenient location to place functionality > that is common across controllers, though I suspect that it is bad > style to do so. > > For example to create a model file called helper.py with the following > contents: > > ---------------------------------------------------------------------------------------- > ## Global Configuration > # Primary navigation menu > MENU = [["Home", URL(r=request, c="default", f="index")], > ["Forum", URL(r=request, c="forum", f="index")], > ["Test", "http://test"]] > > ## Helper functions > def _menu(): > """ > Return the menu as a list of lists where each element > takes the form of [strLinkText, boolIsActiveLink, strLinkUrl] > """ > m = [] > for text, url in MENU: > m.append([text, URL(r=request) == url, url]); > return m > ---------------------------------------------------------------------------------------- > > This enables me to call from every controller function: > > response.menu = _menu() > > > Just the fact that response is in global scope here is very > convenient. However I do not want to violate the MCV pattern, unless > it is acceptable here. Moving this logic into a separate module is > akward, as one has to move varibles back and forth and needs to > restart web2py every so often for changes to the module to take > effect. > > What is best practice, when it comes to sharing code across > controllers please? > > Best regards, > HC > > > -- Timothy Farrell <tfarr...@swgen.com> Computer Guy Statewide General Insurance Agency (www.swgen.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---