Created
February 11, 2012 14:18
-
-
Save ralphbean/1799647 to your computer and use it in GitHub Desktop.
tween for removing jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pyramid.settings import asbool | |
| import tw2.core.core | |
| import tw2.jquery | |
| def remove_jq_factory(handler, registry): | |
| """ In order to use this, you need to add the following you myapp/__init__.py: | |
| config.add_tween('myapp.tween.remove_jq_factory') | |
| """ | |
| def remove_jq_tween(request): | |
| # Send the request on through other tweens and our app | |
| response = handler(request) | |
| # Before the response is modified by the tw2 middleware, let's remove | |
| # jquery_js from its registry. | |
| offending_links = [r.req().link for r in [ | |
| tw2.jquery.jquery_js, | |
| ]] | |
| local = tw2.core.core.request_local() | |
| local['resources'] = [ | |
| r for r in local.get('resources', list()) | |
| if r.link not in offending_links | |
| ] | |
| return response | |
| return remove_jq_tween |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment