diff MoinMoin/events/__init__.py @ 2064:5cc8f6714297

Add more event types. Return a list of messages generated by event handlers to caller.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Thu, 31 May 2007 01:00:27 +0200
parents 7547652ffb6f
children afa784d8d58d
line wrap: on
line diff
--- a/MoinMoin/events/__init__.py	Thu May 31 00:59:42 2007 +0200
+++ b/MoinMoin/events/__init__.py	Thu May 31 01:00:27 2007 +0200
@@ -5,8 +5,8 @@
     This code abstracts event handling in MoinMoin,
     currently for notifications. It implements the observer pattern.
 
-@copyright: 2007 by Karol Nowak <grywacz@gmail.com>
-@license: GNU GPL, see COPYING for details.
+    @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
+    @license: GNU GPL, see COPYING for details.
 """
 
 from MoinMoin import wikiutil
@@ -20,22 +20,40 @@
 
 class Observable:
     """A class handling information common to all events."""
-    pass
+    
+    def __init__(self, request):
+        self.request = request
         
 class PageEvent(Observable):
     """An event related to a page change"""
-    
-    def __init__(self, request, page):
-        self.request = request
-        self.page = page
         
 class PageChangedEvent(PageEvent):
-    pass
+    def __init__(self, request, page, comment, trivial):
+        Observable.__init__(self, request)
+        self.page = page
+        self.comment = comment
+        self.trivial = trivial
+        
 class PageRenamedEvent(PageEvent):
     pass
 class PageDeletedEvent(PageEvent):
     pass
-        
+class FileAttachedEvent(PageEvent):
+    pass
+
+class PageRevertedEvent(PageEvent):
+    def __init__(self, request, pagename, previous, current):
+        Observable.__init__(self, request)
+        self.pagename = pagename
+        self.previous = previous
+        self.current = current    
+
+class SubscribedToPageEvent(PageEvent):
+    def __init__(self, request, pagename, username):
+        Observable.__init__(self, request)    
+        self.pagename = pagename
+        self.username = username
+
 def register_handlers(cfg):
     """Create a list of available event handlers.
     
@@ -57,6 +75,9 @@
 
 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:
@@ -64,4 +85,8 @@
     
     # Try to handle the event with each available handler (for now)
     for handle in event_handlers:
-        handle(event)
\ No newline at end of file
+        retval = handle(event)
+        if isinstance(retval, unicode):
+            msg.append(retval)
+            
+    return msg
\ No newline at end of file