diff MoinMoin/events/__init__.py @ 2152:cf4c4a3d6085

Add a list of selectable events user wants to be notified about.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Mon, 18 Jun 2007 02:14:10 +0200
parents f153b3155240
children 01f05e74aa9c fe37834deb3d
line wrap: on
line diff
--- a/MoinMoin/events/__init__.py	Mon Jun 18 02:12:04 2007 +0200
+++ b/MoinMoin/events/__init__.py	Mon Jun 18 02:14:10 2007 +0200
@@ -17,11 +17,14 @@
 # A list of available event handlers
 _event_handlers = None
 
+# A list of event types that user can subscribe to
+_subscribable_events = None
+
 # Create a list of extension actions from the package directory
 modules = pysupport.getPackageModules(__file__)
 
 
-class Event:
+class Event(object):
     """A class handling information common to all events."""
     def __init__(self, request):
         self.request = request
@@ -34,6 +37,10 @@
 
         
 class PageChangedEvent(PageEvent):
+    
+    description = u"""Page has been modified (edit, creation, deletion)"""
+    req_superuser = False
+    
     def __init__(self, request, page, comment, trivial):
         PageEvent.__init__(self, request)
         self.page = page
@@ -46,6 +53,10 @@
 
 
 class PageDeletedEvent(PageEvent):
+    
+    description = u"""Page has been deleted"""
+    req_superuser = False
+    
     def __init__(self, request, page, comment):
         PageEvent.__init__(self, request)
         self.request = request
@@ -54,6 +65,10 @@
 
 
 class FileAttachedEvent(PageEvent):
+    
+    description = u"""A new attachment has been added"""
+    req_superuser = False
+    
     def __init__(self, request, pagename, attachment_name, size):
         PageEvent.__init__(self, request)
         self.request = request
@@ -63,6 +78,10 @@
 
 
 class PageRevertedEvent(PageEvent):
+    
+    description = u"""A page has been reverted to a previous state"""
+    req_superuser = False
+    
     def __init__(self, request, pagename, previous, current):
         PageEvent.__init__(self, request)
         self.pagename = pagename
@@ -71,6 +90,10 @@
 
 
 class SubscribedToPageEvent(PageEvent):
+    
+    description = u"""An user has subscribed to a page"""
+    req_superuser = True
+    
     def __init__(self, request, pagename, username):
         PageEvent.__init__(self, request)    
         self.pagename = pagename
@@ -79,6 +102,7 @@
 
 class JabberIDSetEvent(Event):
     """ Sent when user changes her Jabber ID """
+    
     def __init__(self, request, jid):
         Event.__init__(self, request)
         self.jid = jid
@@ -88,6 +112,7 @@
     
     Obviously this will be usually sent along with JabberIDSetEvent,
     because we require user's jabber id to be unique by default.
+    
     """
     def __init__(self, request, jid):
         Event.__init__(self, request)
@@ -96,6 +121,9 @@
 class UserCreatedEvent(Event):
     """ Sent when a new user has been created """
     
+    description = u"""A new account has been created"""
+    req_superuser = True
+    
     def __init__(self, request, user):
         Event.__init__(self, request)
         self.user = user
@@ -140,3 +168,22 @@
             msg.append(retval)
             
     return msg
+
+def get_subscribable_events():
+    """Create and return a list of user-visible events
+    
+    @return: A list of user-visible events described by dictionaries
+    @rtype: dict
+    """
+    global _subscribable_events
+    defs = globals()
+    
+    if not _subscribable_events:
+        _subscribable_events = {}
+        
+        for ev in defs.values():
+            if type(ev) is type and issubclass(ev, Event) and ev.__dict__.has_key("description"):
+                _subscribable_events[ev.__name__] = {'desc': ev.description,
+                                                     'superuser': ev.req_superuser}
+    
+    return _subscribable_events