Pylons / pyramid_layout

Pyramid add-on for managing UI layouts.
Other
24 stars 26 forks source link

The pyramid.renderer.render() call needs to be passed with a renderer_name key #30

Open GhitaB opened 10 years ago

GhitaB commented 10 years ago

The bug is in this function in config.py

def derived(context, request, *args, **kw):
    result = wrapped(context, request, *args, **kw)
    if isinstance(result, basestring):
        return result
    system = {'panel': panel,
              'renderer_info': renderer,
              'context': context,
              'request': request
              }
    rendered = renderer.render(result, system, request=request)
    return rendered

The system variable that is passed to the renderer needs to have the renderer_name key, according to the documentation here: http://docs.pylonsproject.org/projects/pyramid/en/master/narr/templates.html#system-values-used-during-rendering

My problem comes from this code in Kotti, that assumes that all system variables (presented as event, in this case), have the renderer_name keyword. Even a None value as renderer_name would suffice, in this case:

def add_renderer_globals(event):
    if event['renderer_name'] != 'json':
        request = event['request']
        api = getattr(request, 'template_api', None)
        if api is None and request is not None:
            api = template_api(event['context'], event['request'])
        event['api'] = api