On Tue, 2012-01-31 at 00:34 +0100, Tom Lazar wrote:
> hi there,
> 
> i was getting tired of either a) having to pass in the request all over the 
> place (mainly from views down to helper methods) in order for the latter to 
> have access to the settings via request.settings or b) having to call 
> get_current_registry() all the time (which would mean my tests require some 
> additional setup foo) so i tried this in the myapp/__init__.py:
> 
> from pyramid.config import Configurator
> settings = dict()
> 
> 
> def main(global_config, **_settings):
>    config = Configurator(settings=_settings)
>    import myapp
>    myapp.settings = _settings
>    config.scan()
>    return config.make_wsgi_app()
> 
> and henceforth wherever i need access to the settings:
> 
> from myapp import settings
> ...
> 
> settings['myapp.foo']
> 
> is this a bad idea? it seems 'dirty' but it would keep my tests and code 
> significantly leaner...
> 
> any opinions?

I think it might be significantly better to just create a settings.py
module in your app and put stuff in there instead of in your config file
if you want globals, because this is effectively a monkeypatch, and
makes bootstrap code very timing-dependent.  Or you could do something
like what's suggested in
<http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/configuration.html#django-style-settings-py-configuration>
 I personally find that global settings makes my test code much more brittle, 
because it means I have to clean up the settings after changing them within 
test code instead of just saying "request.settings = {}". But at the end of the 
day, it's really up to you.

- C


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

Reply via email to