Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New panels ideas and porting existing #11

Open
jettify opened this issue Jun 2, 2015 · 3 comments
Open

New panels ideas and porting existing #11

jettify opened this issue Jun 2, 2015 · 3 comments

Comments

@jettify
Copy link
Member

jettify commented Jun 2, 2015

I've looked around for cool panel in pyramid/django/flask projects:

  1. git history: https://github.com/sjhewitt/django-debug-toolbar-git-panel
  2. plot tables relations for sqlalchemy: https://github.com/uralbash/pyramid_debugtoolbar_sadisplay
  3. replay ajax calls: https://github.com/jvanasco/pyramid_debugtoolbar_ajax

May be we should add some library like: aiohttp_debugtoolbar_extras or own repository for each task.

@RealJTG
Copy link

RealJTG commented Apr 27, 2016

Missing templates panel for aiohttp_jinja2, obviously.

@RealJTG
Copy link

RealJTG commented Jun 6, 2016

Currently trying to port Jinja2 debug panel.
I've added on_jinja2_template_rendered signal to aiohttp_jinja2:

def setup(app, *args, app_key=APP_KEY, context_processors=(), **kwargs):
    ...
    app.on_jinja2_template_rendered = signals.Signal(app)
    ...

def render_string(template_name, request, context, *, app_key=APP_KEY):
    ...
    asyncio.ensure_future(app.on_jinja2_template_rendered.send(app, context))
    ...

and subscribed on it in new debug panel:

class Jinja2DebugPanel(DebugPanel):
    """
    A panel to display Jinja2 template variables.
    """
    name = 'Jinja2'
    has_content = True
    template = 'jinja2.jinja2'
    title = 'Jinja2'
    nav_title = title

    def __init__(self, request):
        super().__init__(request)
        # attach handler
        request.app.on_jinja2_template_rendered.append(self.on_template_rendered)

    def on_template_rendered(self, app, context):
        self.populate(context)
        # detach handler
        app.on_jinja2_template_rendered.remove(self.on_template_rendered)

    def populate(self, context):
        self.data = {'variables': []}
        for name, value in context.items():
            self.data['variables'].append((name, repr(value)))

Works pretty similar to flask-debugtoolbar except they don't need to detach handler each time because there's only one request.
I don't like this approach - weird things happens if two or more handlers left attached (e.g. due to exception between panel initialization and template rendering), but can't figure out how/where to put single handler and how to return captured context. Any suggestions?

@asvetlov
Copy link
Member

asvetlov commented Jun 8, 2016

Calling async signals from sync render_string looks weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants