Pylons/pyramid_layout — pull request #3 by thehunmonkgroup (2012-12-02 01:00:29+00:00)
Title: Better error handling for missing request and layout manager in add_renderer_globals

`add_renderer_globals()` contains some logic that prevents runtime errors in the case where rendering is done from a script, but I found another case where more general error handling will benefit:

* The pyramid_debugtoolbar module is enabled.
* Route is matched via traversal.
* A runtime error occurs prior to the context being found.

In this case, `create_layout_manager()` is never called, but `add_renderer_globals()` is (because the debug toolbar is trying to return the runtime error via a request response, I think).

This is a real pain during development, because the traceback displayed when a runtime error occurs during the building of the context is something like:

```
File "lib/python2.6/site-packages/pyramid_layout-0.4-py2.6.egg/pyramid_layout/config.py", line 35, in add_renderer_globals
layout_manager = request.layout_manager
AttributeError: 'Request' object has no attribute 'layout_manager'
```

Not a terribly useful in this case. :)

The patch refactors the error handling in `add_renderer_globals()` in a more general manner, to support both the case of a missing request and a missing layout manager in the request.