On Thu, 2011-12-01 at 17:30 +0100, Vlad K. wrote: > Hello all! > > > What is the recommended way to fetch registry (settings) for read only > outside of the view (where request object is not available)? I was > looking at the threadlocal.get_current_registry() but the docs say it > should not be used except maybe in unit tests. > > I understand that the request object should be passed around, but what > are my options if I want to avoid that?
To avoid passing deployment settings values around, your options are: - Use get_current_registry() - Use a pattern like http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/configuration.html#django-style-settings-py-configuration You're encouraged to pass per-request values around to make writing unit tests pleasant and to make it possible to use more than one Pyramid app per process. But... If you don't care about testing but you do care about being able to run more than one instance of the application in the same process: def get_setting(setting_name, default=None): return get_current_registry().settings.get('a', default) def somefunction(a, b): beinghosed = get_setting('i-am-hosing-myself') If you care neither about testing nor about being able to run more than one Pyramid application per process, the "django-style settings" cookbook entry linked above puts the gun in your hands; it's pre-pointed at your feet. - 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.
