diff MoinMoin/events/__init__.py @ 2396:cf85b6916d17

Add a PagePreSave event; abort page save if handlers return Abort.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 15 Jul 2007 23:40:40 +0200
parents 53fbdf5899ff
children 245181ec9fe2
line wrap: on
line diff
--- a/MoinMoin/events/__init__.py	Sun Jul 15 05:40:56 2007 +0200
+++ b/MoinMoin/events/__init__.py	Sun Jul 15 23:40:40 2007 +0200
@@ -147,10 +147,32 @@
         Event.__init__(self, request)
         self.user = user
 
+class PagePreSaveEvent(Event):
+    """ Event sent when a page is about to be saved
+
+    This can be used to abort a save, for instance,
+    if handler returns
+
+    """
+    def __init__(self, request, page_editor, new_text):
+        Event.__init__(self, request)
+        self.page_editor = page_editor
+        self.new_text = new_text
+
+
 class EventResult:
     """ This is a base class for messages passed from event handlers """
     pass
 
+class Abort(EventResult):
+    """ Result returned if handler wants to abort operation that sent the event """
+    def __init__(self, reason):
+        """
+        @param reason: human-readable reason of failure
+        """
+        self.reason = reason
+        
+
 def get_handlers(cfg):
     """Create a list of available event handlers.