[CMF-checkins] CVS: Products/CMFCore - ActionInformation.py:1.26.10.2 ActionsTool.py:1.54.2.2

Yvo Schubbe y.2005- at wcm-solutions.de
Tue Jan 25 11:04:50 EST 2005


Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv20915/CMFCore

Modified Files:
      Tag: yuppie-new_actions-branch
	ActionInformation.py ActionsTool.py 
Log Message:
- removed deprecated 'name' and 'permissions' keys from ActionInfo
- allowed 'description' key in ActionInfo
- implemented IAction in the oldstyle ActionInformation class and used this interface to simplify ActionInfo
- updated tests
- some import cleanup


=== Products/CMFCore/ActionInformation.py 1.26.10.1 => 1.26.10.2 ===
--- Products/CMFCore/ActionInformation.py:1.26.10.1	Mon Jan 24 14:31:15 2005
+++ Products/CMFCore/ActionInformation.py	Tue Jan 25 11:04:20 2005
@@ -169,55 +169,38 @@
 class ActionInfo(UserDict):
     """ A lazy dictionary for Action infos.
     """
+
     __implements__ = IActionInfo
+
     __allow_access_to_unprotected_subobjects__ = 1
 
     def __init__(self, action, ec):
-        lazy_keys = []
 
-        if IAction.isImplementedBy(action):
-            self._ec = ec
-            (lazy_map, lazy_keys) = action.getInfoData()
-            UserDict.__init__(self, lazy_map)
-
-        elif isinstance(action, dict):
+        if isinstance(action, dict):
+            lazy_keys = []
             UserDict.__init__(self, action)
-            self.data.setdefault( 'id', self.data['name'].lower() )
-            self.data.setdefault( 'title', self.data['name'] )
+            if 'name' in self.data:
+                self.data.setdefault( 'id', self.data['name'].lower() )
+                self.data.setdefault( 'title', self.data['name'] )
+                del self.data['name']
             self.data.setdefault( 'url', '' )
-            self.data.setdefault( 'permissions', () )
             self.data.setdefault( 'category', 'object' )
             self.data.setdefault( 'visible', True )
             self.data['available'] = True
-
         else:
-            self._action = action
-            self._ec = ec
-            UserDict.__init__( self, action.getMapping() )
-            self.data['name'] = self.data['title']
-            del self.data['description']
-
-            if self.data['action']:
-                self.data['url'] = self._getURL
-                lazy_keys.append('url')
-            else:
-                self.data['url'] = ''
-            del self.data['action']
-
-            if self.data['condition']:
-                self.data['available'] = self._checkCondition
-                lazy_keys.append('available')
-            else:
-                self.data['available'] = True
-            del self.data['condition']
+            # if action isn't a dict, it has to implement IAction
+            (lazy_map, lazy_keys) = action.getInfoData()
+            UserDict.__init__(self, lazy_map)
 
-        if self.data['permissions']:
+        self.data['allowed'] = True
+        permissions = self.data.pop( 'permissions', () )
+        if permissions:
             self.data['allowed'] = self._checkPermissions
             lazy_keys.append('allowed')
-        else:
-            self.data['allowed'] = True
 
+        self._ec = ec
         self._lazy_keys = lazy_keys
+        self._permissions = permissions
 
     def __getitem__(self, key):
         value = UserDict.__getitem__(self, key)
@@ -238,16 +221,6 @@
         else:
             return self.data == other
 
-    def _getURL(self, ec):
-        """ Get the result of the URL expression in the current context.
-        """
-        return self._action._getActionObject()(ec)
-
-    def _checkCondition(self, ec):
-        """ Check condition expression in the current context.
-        """
-        return self._action.testCondition(ec)
-
     def _checkPermissions(self, ec):
         """ Check permissions in the current context.
         """
@@ -263,7 +236,7 @@
             else:
                 context = ec.contexts['portal']
 
-        for permission in self['permissions']:
+        for permission in self._permissions:
             if _checkPermission(permission, context):
                 return True
         return False
@@ -276,6 +249,9 @@
     Actions generate links to views of content, or to specific methods
     of the site.  They can be filtered via their conditions.
     """
+
+    __implements__ = IAction
+
     _isActionInformation = 1
     __allow_access_to_unprotected_subobjects__ = 1
 
@@ -462,6 +438,29 @@
         """ Get a newly-created AI just like us.
         """
         return self.__class__( priority=self.priority, **self.getMapping() )
+
+    security.declarePrivate('getInfoData')
+    def getInfoData(self):
+        """ Get the data needed to create an ActionInfo.
+        """
+        lazy_keys = []
+        lazy_map = self.getMapping()
+
+        if lazy_map['action']:
+            lazy_map['url'] = self._getActionObject()
+            lazy_keys.append('url')
+        else:
+            lazy_map['url'] = ''
+        del lazy_map['action']
+
+        if lazy_map['condition']:
+            lazy_map['available'] = self.testCondition
+            lazy_keys.append('available')
+        else:
+            lazy_map['available'] = True
+        del lazy_map['condition']
+
+        return (lazy_map, lazy_keys)
 
 InitializeClass( ActionInformation )
 


=== Products/CMFCore/ActionsTool.py 1.54.2.1 => 1.54.2.2 ===
--- Products/CMFCore/ActionsTool.py:1.54.2.1	Mon Jan 24 14:31:15 2005
+++ Products/CMFCore/ActionsTool.py	Tue Jan 25 11:04:20 2005
@@ -24,7 +24,6 @@
 from ActionInformation import ActionInformation
 from ActionProviderBase import ActionProviderBase
 from Expression import Expression
-from interfaces.portal_actions import Action as IAction
 from interfaces.portal_actions import ActionCategory as IActionCategory
 from interfaces.portal_actions import ActionProvider as IActionProvider
 from interfaces.portal_actions import portal_actions as IActionsTool



More information about the CMF-checkins mailing list