Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Created February 11, 2012 14:18
Show Gist options
  • Select an option

  • Save ralphbean/1799647 to your computer and use it in GitHub Desktop.

Select an option

Save ralphbean/1799647 to your computer and use it in GitHub Desktop.
tween for removing jquery
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