Hi everyone, I was unsubscribed to pylons-discuss for a few weeks without realizing it. I was wondering why the mail activity was so low. :)
On Tue, Nov 2, 2010 at 2:04 AM, Juliusz Gonera <[email protected]> wrote: > Wyatt Baldwin wrote: > >> You can't use `pylons.config` at the module level (generally >> speaking), because it's only set in the context of a request. >> >> So, you can access it from within in a model class method in the >> context of a request. Another option is to call a `model.init(config)` >> function from `load_environment` to set up the model. The default Pylons-SQLAlchemy configuration has an ``init_model(engine)`` function in the model, which is called in load_environment. You can add whatever arguments you need: def init_model(engine1, engine2): def init_model(engine, my_config_variable): def init_model(engine, config): In general it's good to not let the model have dependencies on other parts of Pylons (e.g., imports, special globals). That way you can import the model in a standalone utility script, call init_model, and it will be ready to use even if other parts of the application are broken. In general, the special globals (pylons.request, pylons.config, pylons.session, pylons.url, pylons.tmpl_context) are not available outside a request. There are some exceptions; e.g., for test initialization, but it's easier not to use the globals than to figure out when exactly each global is available, and you can always ask on the list if you need a particular one some situation. -- Mike Orr <[email protected]> -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
