Skip to content

Commit

Permalink
Merge pull request #291 from mmerickel/request.toolbar_panels
Browse files Browse the repository at this point in the history
add the request.toolbar_panels property
  • Loading branch information
mmerickel authored May 3, 2017
2 parents 6103a27 + 4e87d47 commit ba43d2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Unreleased
``config.add_debugtoolbar_panel`` and per-panel ``includeme`` functions.
See https://github.com/Pylons/pyramid_debugtoolbar/pull/288

- Exposed a ``request.toolbar_panels`` dictionary which can be used from within
``DebugPanel.render_content`` and ``DebugPanel.render_vars`` in order to
introspect and use the data generated by other panels when rendering the
panel. See https://github.com/Pylons/pyramid_debugtoolbar/pull/291

3.0.5 (2016-11-1)
-----------------

Expand Down
5 changes: 5 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ add the panel to their ``debugtoolbar.includes`` setting in their app.
The source code for the standard debugpanel ``request_vars.py`` is a good
starting point for inspiration.

The ``render_vars`` and ``render_content`` methods may use the
``request.toolbar_panels`` dictionary to introspect and work with other panels
that captured data for the original request. The dictionary keys are the names
of other panels and the values are the panel instances.

Configuring an application to use the panel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
8 changes: 8 additions & 0 deletions pyramid_debugtoolbar/toolbar_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def request_view(request):
request_id = request.matchdict.get('request_id', last_request_id)
toolbar = history.get(request_id, None)

# set a dictionary of panels that can be accessed inside
# DebugPanel.render_content()
if toolbar:
request.toolbar_panels = {
panel.name: panel
for panel in toolbar.panels
}

static_path = request.static_url(STATIC_PATH)
root_path = request.route_url(ROOT_ROUTE_NAME)

Expand Down

0 comments on commit ba43d2a

Please sign in to comment.