Last active
April 9, 2018 16:06
-
-
Save pgrunewald/63210f87eb7a4171d683576cfb6082a9 to your computer and use it in GitHub Desktop.
Disable Theming/Diazo for AJAX Requests
This file contains 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
<configure | |
xmlns = "http://namespaces.zope.org/zope" | |
xmlns:five = "http://namespaces.zope.org/five" | |
xmlns:genericsetup = "http://namespaces.zope.org/genericsetup" | |
xmlns:monkey = "http://namespaces.plone.org/monkey" | |
i18n_domain = "tud.profiles.webcms"> | |
<!-- Disable Theming/Diazo in transformation chain if appropriate --> | |
<adapter | |
name="your.addon.disable_theme" | |
for="* your.addon.interfaces.IThemeSpecific" | |
factory=".disable_theme.DisableThemeTransform" | |
provides="plone.transformchain.interfaces.ITransform" | |
/> | |
</configure> |
This file contains 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
"""Transformation to disable Theming/Diazo | |
""" | |
from zope.interface import implements | |
from plone.transformchain.interfaces import ITransform | |
class DisableThemeTransform(object): | |
"""This transformation will be called right BEFORE diazo transforms. | |
See for reference: | |
* lxml transforms (e.g. plone.app.blocks, collectivexdv) => 8000-8999 | |
* gzip => 10000 | |
* caching => 12000 | |
""" | |
implements(ITransform) | |
# Calling order | |
order = 7999 | |
def __init__(self, published, request): | |
self.published = published | |
self.request = request | |
def disable_theme(self): | |
# List here conditions that would justify the disabling of the theme. | |
ajax_request = self.request.environ.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' | |
if ajax_request: | |
return self.request.response.setHeader('X-Theme-Disabled', 'True') | |
def transformString(self, result, encoding): | |
"""See IFilter implementation""" | |
self.disable_theme() | |
return result | |
def transformUnicode(self, result, encoding): | |
"""See IFilter implementation""" | |
self.disable_theme() | |
return result | |
def transformIterable(self, result, encoding): | |
"""See IFilter implementation""" | |
self.disable_theme() | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment