Zope Lifecycle Events

6.0 · active · verified Thu Apr 16

Zope.lifecycleevent provides a standard set of event objects and convenience functions for describing the lifecycle of objects within a Zope application or any Python system using `zope.event`. This includes events for object creation, modification, addition, removal, and copying. The library is currently at version 6.0 and actively maintained, with new minor versions typically released every 2-6 months and major versions every 2-3 years, aligning with the broader Zope ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an object and dispatch standard lifecycle events such as `created` and `modified` using the convenience functions provided by `zope.lifecycleevent`. It also shows how to include specific modification descriptions using `Attributes` for the `modified` event. To make these events have an effect, you would typically configure event subscribers within your application, often using `zope.component` in a Zope/Plone environment.

from zope.lifecycleevent import created, modified, Attributes

class Document:
    def __init__(self, title, content):
        self.title = title
        self.content = content

    def update(self, new_content):
        old_content = self.content
        self.content = new_content
        # Example of sending a modified event with attribute description
        # In a real app, you'd likely define an IFile interface for 'content'
        modified(self, Attributes(None, 'content'))
        print(f"Document '{self.title}' content updated and modified event sent.")

# Create an object and send a creation event
doc = Document("My First Doc", "Initial content.")
created(doc)
print(f"Document '{doc.title}' created and event sent.")

# Modify the object and send a modification event
doc.update("New updated content.")

# Note: To actually *handle* these events, you would need to set up 
# subscribers using zope.event.notify and zope.component.provideHandler (not shown here).

view raw JSON →