>
> 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.
>
After accepting the submitted registration form, the register() function 
will pass the processed registration SQLFORM object to each 
register_onaccept function. It's just a regular SQLFORM object 
(post-processing), so it has form.vars, etc. Note, you don't have to call 
it "form" in your lambda function definition.
 

> 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?
>
Yes, this is fine, but you shouldn't duplicate any code. Instead, if there 
is model code needed for more than one controller (including the database 
connection statement), you should put that in the root /models folder so it 
gets executed before the controller-specific model files.

Anthony 
 

-- 



Reply via email to