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

Reply via email to