Skip to content

Instantly share code, notes, and snippets.

@mitchellrj
Created April 10, 2012 10:27
Show Gist options
  • Save mitchellrj/2350190 to your computer and use it in GitHub Desktop.
Save mitchellrj/2350190 to your computer and use it in GitHub Desktop.
Make Plone object undeletable but still work with iterate / stagingbehavior
<configure xmlns="http://namespaces.zope.org/zope">
<subscriber
for=".interfaces.IMyType
OFS.interfaces.IObjectWillBeRemovedEvent"
handler=".events.event_handler"
/>
</configure>
from AccessControl import Unauthorized
try:
from plone.app.iterate.interfaces import CheckinException
from plone.app.iterate.interfaces import IObjectCopier
HAS_ITERATE = True
except ImportError:
# No iterate available
HAS_ITERATE = False
from zope.component import queryAdapter
def event_handler(object, event):
if HAS_ITERATE:
copier = queryAdapter(object, IObjectCopier)
baseline = None
try:
baseline = copier._getBaseline()
except CheckinException:
pass
if baseline is not None:
# This is a working copy created by plone.app.iterate /
# plone.app.stagingbehavior. We need to be able to move and delete
# these.
return
raise Unauthorized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment