-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 05/17/2013 02:47 PM, Jonathan Vanasco wrote:
> I've got a subscriber to before_render that does some "tweaking" of
> objects and priming of an object cache for Mako/Jinja/etc templates.
>
> The problem that I've run into � json calls to the api trigger this.
>
> The following code works, just wondering if anyone has a better idea ,
> that would let me escape not out of '/api' calls, but anything
> matching a json/jsonp or other render type.
>
>
> def BeforeRender_prime(event): request = event.get("request") or
> threadlocal.get_current_request() if not request : log.debug(
> "BeforeRender_prime | NO_REQUEST" ) return # only run once ; a fix for
> the pyramid_debugtoolbar multiple request if hasattr( request ,
> 'BeforeRender_prime' ): return request.BeforeRender_prime = True #
> don't run on /api , which is all json if request.path_info[:5] ==
> '/api/': return
You should be able to filter on the 'renderer_name' for the event, e.g.:
if event.get('renderer_name') == 'json':
return
Tres.
- --
===================================================================
Tres Seaver
+1 540-429-0999 tse...@palladion.com
Palladion Software "Excellence by Design"
http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with undefined -
http://www.enigmail.net/
iEYEARECAAYFAlGWfzIACgkQ+gerLs4ltQ5mjQCgkF0xx9l0VdQced9EtS8KPcLR
ecAAn1LEU4jNsN4Bj+P+SZ68Uv98VVPJ
=tDsQ
-----END PGP SIGNATURE-----