view MoinMoin/events/ @ 2091:7af58454aafa

Send an event when user changes her jabber id, force jid to be unique.
author Karol 'grzywacz' Nowak <>
date Sun, 03 Jun 2007 21:56:02 +0200
parents c8bc6df45964
children 9ee68c8b409b
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - event (notification) framework

    This code abstracts event handling in MoinMoin,
    currently for notifications. It implements the observer pattern.

    @copyright: 2007 by Karol Nowak <>
    @license: GNU GPL, see COPYING for details.

from MoinMoin import wikiutil
from MoinMoin.util import pysupport
from MoinMoin.wikiutil import PluginAttributeError

# A list of available event handlers
event_handlers = None

# Create a list of extension actions from the package directory
modules = pysupport.getPackageModules(__file__)

class Event:
    """A class handling information common to all events."""
    def __init__(self, request):
        self.request = request

class PageEvent(Event):
    """An event related to a page change"""

class PageChangedEvent(PageEvent):
    def __init__(self, request, page, comment, trivial):
        Event.__init__(self, request) = page
        self.comment = comment
        self.trivial = trivial

class PageRenamedEvent(PageEvent):
class PageDeletedEvent(PageEvent):
class FileAttachedEvent(PageEvent):

class PageRevertedEvent(PageEvent):
    def __init__(self, request, pagename, previous, current):
        Event.__init__(self, request)
        self.pagename = pagename
        self.previous = previous
        self.current = current    

class SubscribedToPageEvent(PageEvent):
    def __init__(self, request, pagename, username):
        Event.__init__(self, request)    
        self.pagename = pagename
        self.username = username

class JabberIDSetEvent(Event):
    """ Sent when user changes her Jabber ID """
    def __init__(self, request, jid):
        Event.__init__(self, request)
        self.jid = jid

def register_handlers(cfg):
    """Create a list of available event handlers.
    Each handler is a handle() function defined in an plugin,
    pretty much like in case of actions.
    TODO: maybe make it less dumb? ;-)"""
    global event_handlers

    event_handlers = []
    names = wikiutil.getPlugins("events", cfg)

    for name in names:
            handler = wikiutil.importPlugin(cfg, "events", name, "handle")
        except PluginAttributeError:
            handler = None
        if handler is not None:

def send_event(event):
    """Function called from outside to process an event"""
    # A list of messages generated by event handlers, passed back to caller
    msg = []
    # Find all available event handlers
    if event_handlers is None:
    # Try to handle the event with each available handler (for now)
    for handle in event_handlers:
        retval = handle(event)
        if isinstance(retval, unicode):
    return msg