pyramid_debugtoolbar icon indicating copy to clipboard operation
pyramid_debugtoolbar copied to clipboard

Suggestion: `Session` panel

Open jvanasco opened this issue 8 years ago • 2 comments

I wrote a custom variation of this idea and wanted to suggest it upstream after seeing the 4.1 announcement

We split sessions into a separate panel so that the data can be captured BEFORE and AFTER the request is processed, then show the info side-by-side on a table. I forget where the toolbar currently captures data, but it's only one.

jvanasco avatar May 31 '17 17:05 jvanasco

Right now we snapshot the session upon first access. Tracking its updated state and visualizing the changes sounds nice.

mmerickel avatar Jun 08 '17 02:06 mmerickel

It's a lifesaver. We don't use Pyramid's stock sessions, so my panel is incompatible as-is. I don't know when I'll have time to port, but will try to.

If anyone wants to tackle it before I get to this, this is generally what we have running:

in our panel sessions.py:

class SessionDebugPanel(DebugPanel):

    # we need the request in the response phase
    __request = None

    def __init__(self, request):
        self.__request = request  # stash for response
        self.data = data = {'session_request': None,
                            'session_response': None,
                            }
        _request_attrs = request.__dict__.copy()
        if 'session' in _request_attrs:
            data.update({'session_request': _request_attrs['session']}
        
    def process_response(self, response):
        _request_attrs = self.__request.__dict__.copy()
        if 'session' in _request_attrs:
            data.update({'session_response': _request_attrs['session']}

the display html just creates a table of all the keys present in both, then iterates them as:

<tr><th>key</th>
       <td>request</td>
       <td>response</td>
       </tr>

jvanasco avatar Jun 08 '17 16:06 jvanasco