On Jun 27, 2012, at 5:52 AM, cyan wrote: > 1. In the web2py book, there is an example for Auth settings, which > presumably resides at top-level inside a model: > > > auth.settings.register_onaccept.append(lambda form: > mail.send(to='[email protected]', subject='new user', message="new user email > is %s' % form.vars.email)) > > and I wonder where exactly do these 'form' and 'form.vars.email' variables > come from and how do we know which specific variables are available for which > functions in web2py, such information seems to be poorly documented in the > manual. >
'form' here is a formal argument to the lambda expression, and not otherwise a variable. Have a look at the standard Python docs for more on lambdas. web2py globals have their own section in the book: http://web2py.com/books/default/chapter/29/4#API > 2. Is it advisable to organize models into different folders named by their > related controllers? For example, for all account-related functionalities, I > create a model called 'account.py' and put it at > 'my_app/models/account/account.py', so that only this model will be executed > for all account-related requests. Similarly, a model named 'content.py' is > created in 'my_app/models/content/content.py', so that only this model will > be executed for all the requests relating to user-generated content. By doing > this (as opposed to put all the models in 'my_app/models/'), we can avoid > executing models we don't need for certain requests, but we may need to > duplicate some code (e.g. create db connections) for different models. Is > this a good practice in web2py? > I'd say it's generally premature optimization. That said, I do a little of that myself, but via conditional logic in a common model (db.py) that looks at request.controller to decide which actions to take. --

