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

Already on GitHub? Sign in to your account

BeforeRender template variables are not displayed in debug toolbar #47

Closed
domenkozar opened this Issue Nov 30, 2011 · 13 comments

Comments

Projects
None yet
5 participants
Member

domenkozar commented Nov 30, 2011

One would expect "Renderings" to include such variables under "System Values" or completely another section.

Owner

mcdonc commented Nov 30, 2011

This is an artifact of how we capture renderings. The renderings panel registers a subscriber itself of BeforeRender; subscribers are not guaranteed to be called in any particular order though, so the toolbar BeforeRender subscriber is likely called before yours. Not sure exactly how to fix this.

Owner

mmerickel commented Sep 16, 2015

This should no longer be an issue as the toolbar's BeforeRender subscriber is in a separate pyramid app now.

@mmerickel mmerickel closed this Sep 16, 2015

Owner

bertjwregeer commented Sep 16, 2015

I am not sure that this is no longer an issue...

I think what @domenkozar was talking about is that his application has a BeforeRender subscriber, and he adds new variables other than the existing Pyramid system variables, however they are not being captured by the Pyramid debugtoolbar.

Unless the debugtoolbar now captures the data being sent to a renderer in a way other than using a BeforeRender subscriber, this will still be the case as the custom BeforeRender that adds extra values to the renderer may be executed AFTER debugtoolbar has captured the variables.

Owner

mmerickel commented Sep 16, 2015

You're right, thanks for double-checking.

I have no idea how we would solve this without monkey patching the RendererHelper or something.

@mmerickel mmerickel reopened this Sep 16, 2015

Contributor

jvanasco commented Jan 21, 2016

I ran into this issue recently too - I have a BeforeRender that populates the templating space with some constants and helper functions, and needed to support them on my custom panels.

Since I use custom panels, my fix was to use a factory to generate the data dict (which pre-populates the namespace).

An approach I thought of taking though, was to have an environment.ini config option that will take a a dotted namepace for events (such as BeforeRender) and then register them into the app.

example:

debugtoolbar.events.BeforeRender = myapp.events.BeforeRender_a myapp.events.BeforeRender_b
Owner

mmerickel commented Jan 21, 2016

@jvanasco I have no idea what you just said but my first impression is that you may want a custom BeforeRender subscribed for your panel template?

Contributor

jvanasco commented Jan 21, 2016

rephrased: If I understand correctly, the OP's problem would be solved by using an .ini option to subscribe BeforeRender events onto panel templates.

I solved my variation by replacing:

 self.data = {'request', request... }

with

 self.data = custom_dictionary_factory()
 self.data['request']= request
 ...
Owner

mmerickel commented Jan 21, 2016

Okay, I don't think you understand the original issue correctly.

The issue is the debug toolbar registers a BeforeRender subscriber on the parent application in order to capture data and display it on the panel. The subscribers have an ordering and each one is mutating the event dictionary adding its values. Thus, the toolbar's subscriber only knows about the state of the dictionary when it's invoked and any subscribers invoked afterward do not show up in the dictionary and thus are missing from the panel.

Contributor

jvanasco commented Jan 21, 2016

I thought the renderers no longer run on the debugtoolbar panel because it's now in a separate app (per the Sep 15, 2015 comment above).

Owner

mmerickel commented Jan 21, 2016

You're missing the point. The toolbar registers a before render subscriber on the parent application as a way to figure out what variables were passed to the parent application's templates.

Member

domenkozar commented Dec 7, 2016

We'd essentially have to implement a sort for BeforeRender subscriber to be able to say debug_toolbar comes last.

Owner

mmerickel commented Dec 7, 2016

This is possible to do, but requires some hairy, internal, private hacking of the subscriber order in the registry which is controlled by zope.interface. To do it properly it'd be done in a ApplicationCreated event probably. The code would have to search for the subscriber, remove it, and re-add it to ensure it's last in the order. Alternatively it could just register itself directly into the registry instead of using config.add_subscriber.

Owner

mmerickel commented Apr 21, 2017

Closed via #284.

@mmerickel mmerickel closed this Apr 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment