Document Actions

Skin switching with pre-traversal

Filed Under:

collective.skinswitcher uses a pre-traversal hook now instead of an access rule.

For collective.editskinswitcher David Convent gave me the idea to get rid of the Access Rule and use a pre-traversal hook instead. That turned out to be pretty easy to do. This looks far cleaner to me. So collective.editskinswitcher is now available as version 0.3. Thanks for the idea David!

It now has an own Product page on plone.org too. Not much is there yet. For downloads just use the cheese shop. If you are using it, drop me a note: it would be nice to know.

Let me show some code. We subscribe to an event in configure.zcml:

<subscriber
    for="*
         zope.app.publication.interfaces.IBeforeTraverseEvent"
    handler=".traversal.switch_skin"
    />

And in traversal.py you then have this code:

def switch_skin(object, event):
    """Switch to the Plone Default skin when we are editing.
    """
    context = object
    request = event.request
    portal_props = getToolByName(context, 'portal_properties')
    editskin_props = portal_props.get('editskin_switcher')
    edit_skin = editskin_props.getProperty('edit_skin', '')
    ...
    context.changeSkin(edit_skin, request)

Well, the code is slightly longer, but this should give you an idea. Except for details this is the same code as was in the External Method, which is now gone.

All in all, for this change one file was added: traversal.py. And various files could be removed, mainly: Extensions/* and setuphandlers.py.

More importantly: if you now remove this package from your zope instance without properly uninstalling it, you are not left with an ExternalMethod in your Plone Site that gives errors because the file is not available anymore.

BTW, if you are using this package already, it is best to uninstall version 0.2 and then install version 0.3; that way the quick installer will take care of removing that external method with the access rule for you.