Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Zope 2 post-publication hook

Project Description


This package is provided for backwards compatibility. New code should use the publication events introduced in Zope 2.12 directly.

For Zope 2.10, a backport of the publication events is available in ZPublisherEventsBackport. This is required for this package and may be added to your buildout directly, or by specifying the ‘Zope2.10’ extra:

eggs =
    plone.postpublicationhook [Zope2.10]


This package provides a hook into Zope’s ZPublisher that is run after the publisher has completed publication, but before the the transaction is committed and the response is returned to the requesting browser. This is practical for caching purposes: it is the ideal place to determine and insert caching headers into the response.

Hooks use zope.event’s event mechanism using the plone.validatehook.interfaces.IPostValidationEvent. This is based on the standard ObjectEvent from zope.component.


As an example we will write a bit of code which logs the path of every published object. This is the code for the event handler:

from zope.interface import Interface
from zope.component import adapter
from plone.postpublicationhook.interfaces import IAfterPublicationEvent
import logging

logger = logging.getLogger("LogRequest")

@adapter(Interface, IAfterPublicationEvent)
def LogRequest(object, event):
    if getattr(object, "getPhysicalPath", None) is None:
        path="Unknown path"
        path="/".join(object.getPhysicalPath()"Request for object %s" % path)

To use this code you need to register it in zcml:

<subscriber handler=".events.LogRequest" />

Using ZPublisher events directly

The IPubBeforeCommit event is equivalent to the IAfterPublicationEvent, however it is not an ObjectEvent so there are a few changes:

from zope.component import adapter
from ZPublisher.interfaces import IPubBeforeCommit
import logging

logger = logging.getLogger("LogRequest")

def LogRequest(event):
    request = event.request
    object = request['PUBLISHED']
    if getattr(object, "getPhysicalPath", None) is None:
        path="Unknown path"
        path="/".join(object.getPhysicalPath()"Request for object %s" % path)

Register it in zcml the same way:

<subscriber handler=".events.LogRequest" />


1.1 - 2010-06-08

  • General and metadata cleanup. [hannosch]
  • Refactor to use ZPublisher publication events (available in Zope 2.10 with ZPublisherEventsBackport.) [lrowe]

1.0rc1 - 2008-10-15

  • Initial release [wichert]

Release History

This version
History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(10.5 kB) Copy SHA256 Hash SHA256
Source None Jun 8, 2010

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate