pyramid: Fix problem with adding '_' to renderer globals.

- Problem occures only when executing pyramid views.
This commit is contained in:
Johannes Bornhold 2016-05-24 15:38:02 +02:00
parent faab12bfec
commit 26d1f8ea5c

View file

@ -21,6 +21,7 @@
import pylons
from pyramid.i18n import get_localizer, TranslationStringFactory
from pyramid.threadlocal import get_current_request
tsf = TranslationStringFactory('rc_root')
@ -33,8 +34,11 @@ def add_renderer_globals(event):
event['c'] = pylons.tmpl_context
event['url'] = pylons.url
# TODO: When executed in pyramid view context the request is not available
# in the event. Find a better solution to get the request.
request = event['request'] or get_current_request()
# Add Pyramid translation as '_' to context
request = event['request']
event['_'] = request.translate
event['localizer'] = request.localizer