Skip to content
This repository has been archived by the owner on Feb 12, 2020. It is now read-only.

Commit

Permalink
Refactor to use the new ZPublisher publication events
Browse files Browse the repository at this point in the history
  • Loading branch information
lrowe committed Nov 6, 2009
1 parent 63e0546 commit c23e953
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 155 deletions.
42 changes: 42 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
Note
====

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
plone.postpublicationhook [Zope2.10]

Introduction
============

Expand Down Expand Up @@ -38,6 +52,34 @@ 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")

@adapter(IPubBeforeCommit)
def LogRequest(event):
request = event.request
object = request['PUBLISHED']
if getattr(object, "getPhysicalPath", None) is None:
path="Unknown path"
else:
path="/".join(object.getPhysicalPath()

logger.info("Request for object %s" % path)


Register it in zcml the same way::

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

.. _zope.event: http://pypi.python.org/pypi/zope.event
.. _zope.component: http://pypi.python.org/pypi/zope.component
.. ZPublisherEventsBackport: http://pypi.python.org/pypi/ZPublisherEventsBackport
6 changes: 6 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

1.0rc2 - Unreleased
-------------------------

* Backport ZPublisher publication events from Zope 2.12
[lrowe]

1.0rc1 - October 15, 2008
-------------------------

Expand Down
6 changes: 1 addition & 5 deletions plone/postpublicationhook/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@

def initialize(context):
from plone.postpublicationhook.hook import InstallHook

InstallHook()
# make it a package
12 changes: 10 additions & 2 deletions plone/postpublicationhook/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five">
xmlns:zcml="http://namespaces.zope.org/zcml">

<five:registerPackage package="." initialize=".initialize" />
<include
zcml:condition="not-installed ZPublisher.interfaces"
package="ZPublisherEventsBackport"
/>

<subscriber
for="ZPublisher.interfaces.IPubBeforeCommit"
handler=".event.redispatch"
/>

</configure>
7 changes: 7 additions & 0 deletions plone/postpublicationhook/event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from zope.interface import implements
from zope.component.interfaces import ObjectEvent
from zope.event import notify
from plone.postpublicationhook.interfaces import IAfterPublicationEvent


Expand All @@ -11,3 +12,9 @@ def __init__(self, context, request):
self.request=request


def redispatch(event):
"""Redispatch IPubBeforeCommit as IAfterPublicationEvent
"""
request = event.request
object = request['PUBLISHED']
notify(AfterPublicationEvent(object, request))
147 changes: 0 additions & 147 deletions plone/postpublicationhook/hook.py

This file was deleted.

5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os.path

version = '1.0'
version = '1.1'

setup(name='plone.postpublicationhook',
version=version,
Expand Down Expand Up @@ -31,5 +31,8 @@
'zope.interface',
'zope.security',
],
extras_require={
'Zope2.10': ['ZPublisherEventsBackport'],
},
)

0 comments on commit c23e953

Please sign in to comment.