[Zope-CVS] CVS: Products/EventListenerTool - ListenerTool.py:1.3

Chris McDonough chrism@zope.com
Wed, 8 Jan 2003 14:37:37 -0500


Update of /cvs-repository/Products/EventListenerTool
In directory cvs.zope.org:/tmp/cvs-serv32763

Modified Files:
	ListenerTool.py 
Log Message:
Merge changes from Tres into public package.


=== Products/EventListenerTool/ListenerTool.py 1.2 => 1.3 ===
--- Products/EventListenerTool/ListenerTool.py:1.2	Tue Jan  7 15:24:55 2003
+++ Products/EventListenerTool/ListenerTool.py	Wed Jan  8 14:37:03 2003
@@ -47,6 +47,17 @@
     _EVENT_REGISTRY_LOOKUP = new_lookup
     return old_value
 
+def _setEventRegistryEnumeration( new_enumeration ):
+
+    """ Override standard registry lookup function.
+    
+    o ONLY FOR TESTING PURPOSES!!!
+    """
+    global _EVENT_REGISTRY_ENUMERATION
+    old_value = _EVENT_REGISTRY_ENUMERATION
+    _EVENT_REGISTRY_ENUMERATION = new_enumeration
+    return old_value
+
 def _setLogger( new_logger ):
 
     """ Override standard logger.
@@ -66,6 +77,8 @@
     __implements__ = ( IEventListenerRule, ISubscriber )
     meta_type = 'Event Listener Rule'
 
+    _enabled = 1
+
     security = ClassSecurityInfo()
 
     def __init__( self, moniker, condition, actions ):
@@ -98,6 +111,17 @@
         """
         return self._actions
 
+    def isEnabled( self ):
+
+        """ See IEventListenerRule.
+        """
+        return self._enabled
+
+    def setEnabled( self, flag ):
+
+        """ See IEventListenerRule.
+        """
+        self._enabled = not not flag
     #
     #   ISubscriber implementation
     #
@@ -117,6 +141,9 @@
 
         """ Does 'event' pass our filter?
         """
+        if not self._enabled:
+            return 0
+        
         interface = _EVENT_REGISTRY_LOOKUP( self._moniker )
         if not interface.isImplementedBy( event ):
             return 0
@@ -310,7 +337,7 @@
     security.declarePrivate( 'manage_beforeDelete' )
     def manage_beforeDelete( self, item, container ):
 
-        self.unsubscribe()
+        self.deactivate()
         Folder.manage_beforeDelete( self, item, container )
         
 
@@ -384,6 +411,20 @@
 
         REQUEST['RESPONSE'].redirect( '%s/manage_listenerRules'
                                       '?manage_tabs_message=Rule+added'
+                                    % self.absolute_url()
+                                    )
+
+    security.declareProtected( ManageEventListener, 'manage_toggleRule' )
+    def manage_toggleRule( self, rule_id, REQUEST ):
+
+        """ POST dispatcher.
+        """
+        rule = self.getRule( rule_id )
+
+        rule.setEnabled( not rule.isEnabled() )
+
+        REQUEST['RESPONSE'].redirect( '%s/manage_listenerRules'
+                                      '?manage_tabs_message=Rule+toggled'
                                     % self.absolute_url()
                                     )