changeset 2095:258d6e648eca

Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Tue, 05 Jun 2007 00:47:10 +0200
parents 9ee68c8b409b
children b37dd51e566e
files MoinMoin/events/JabberNotification.py MoinMoin/events/__init__.py MoinMoin/userform.py
diffstat 3 files changed, 32 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/events/JabberNotification.py	Tue Jun 05 00:38:41 2007 +0200
+++ b/MoinMoin/events/JabberNotification.py	Tue Jun 05 00:47:10 2007 +0200
@@ -9,7 +9,7 @@
 """
 
 import xmlrpclib
-from MoinMoin.events import PageEvent, PageChangedEvent, JabberIDSetEvent
+from MoinMoin.events import *
 from MoinMoin.events.notification_common import page_changed_notification
 
 
@@ -33,10 +33,15 @@
     if isinstance(event, PageEvent):
         handle_page_changed(event)
     elif isinstance(event, JabberIDSetEvent):
-        handle_jid_changed(event)
+        handle_jid_set(event)
+    elif isinstance(event, JabberIDUnsetEvent):
+        handle_jid_unset(event)
 
-def handle_jid_changed(event):
-    print "JID changed"
+def handle_jid_set(event):
+    pass
+
+def handle_jid_unset(event):
+    pass
 
 def handle_page_changed(event):
     """ Handles events related to page changes """
--- a/MoinMoin/events/__init__.py	Tue Jun 05 00:38:41 2007 +0200
+++ b/MoinMoin/events/__init__.py	Tue Jun 05 00:47:10 2007 +0200
@@ -15,7 +15,7 @@
 
 
 # A list of available event handlers
-event_handlers = None
+_event_handlers = None
 
 # Create a list of extension actions from the package directory
 modules = pysupport.getPackageModules(__file__)
@@ -70,8 +70,17 @@
         Event.__init__(self, request)
         self.jid = jid
         
-
-def register_handlers(cfg):
+class JabberIDUnsetEvent(Event):
+    """ Sent when Jabber ID is no longer used
+    
+    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)
+        self.jid = jid
+        
+def _register_handlers(cfg):
     """Create a list of available event handlers.
     
     Each handler is a handle() function defined in an plugin,
@@ -79,9 +88,9 @@
     
     TODO: maybe make it less dumb? ;-)"""
     
-    global event_handlers
+    global _event_handlers
 
-    event_handlers = []
+    _event_handlers = []
     names = wikiutil.getPlugins("events", cfg)
 
     for name in names:
@@ -91,7 +100,7 @@
             handler = None
         
         if handler is not None:
-            event_handlers.append(handler)
+            _event_handlers.append(handler)
 
 
 def send_event(event):
@@ -101,11 +110,11 @@
     msg = []
     
     # Find all available event handlers
-    if event_handlers is None:
-        register_handlers(event.request.cfg)
+    if _event_handlers is None:
+        _register_handlers(event.request.cfg)
     
     # Try to handle the event with each available handler (for now)
-    for handle in event_handlers:
+    for handle in _event_handlers:
         retval = handle(event)
         if isinstance(retval, unicode):
             msg.append(retval)
--- a/MoinMoin/userform.py	Tue Jun 05 00:38:41 2007 +0200
+++ b/MoinMoin/userform.py	Tue Jun 05 00:47:10 2007 +0200
@@ -9,7 +9,7 @@
 
 import time
 from MoinMoin import user, util, wikiutil
-from MoinMoin.events import send_event, JabberIDSetEvent
+from MoinMoin.events import send_event, JabberIDSetEvent, JabberIDUnsetEvent
 from MoinMoin.widget import html
 
 _debug = 0
@@ -244,8 +244,10 @@
                     return _("This jabber id already belongs to somebody else.")
             
             if jid_changed:
-                event = JabberIDSetEvent(self.request, theuser.jid)
-                send_event(event)
+                set_event = JabberIDSetEvent(self.request, theuser.jid)
+                unset_event = JabberIDUnsetEvent(self.request, theuser.jid)
+                send_event(set_event)
+                send_event(unset_event)
 
         if not 'aliasname' in theuser.auth_attribs:
             # aliasname