[CMF-checkins] CVS: Products/CMFCore - ActionInformation.py:1.21 ActionProviderBase.py:1.25

Grégoire Weber zope.org at incept.ch
Wed Jun 30 11:40:47 EDT 2004


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

Modified Files:
	ActionInformation.py ActionProviderBase.py 
Log Message:
- it's now possible to edit properties of an existing action directly. Example: action_provider.getActionObject('object/view').edit(title='Another Title') sets the title to a new value.


=== Products/CMFCore/ActionInformation.py 1.20 => 1.21 ===
--- Products/CMFCore/ActionInformation.py:1.20	Thu Apr 29 12:13:16 2004
+++ Products/CMFCore/ActionInformation.py	Wed Jun 30 11:40:17 2004
@@ -15,8 +15,6 @@
 $Id$
 """
 
-from types import StringType
-
 from AccessControl import ClassSecurityInfo
 from Globals import InitializeClass
 from Acquisition import aq_base, aq_inner, aq_parent
@@ -27,6 +25,8 @@
 from utils import getToolByName
 
 
+_unchanged = [] # marker
+
 class ActionInformation( SimpleItem ):
 
     """ Represent a single selectable action.
@@ -52,21 +52,54 @@
                 ):
         """ Set up an instance.
         """
-        if condition and type( condition ) == type( '' ):
-            condition = Expression( condition )
-
-        if action and type( action ) == type( '' ):
-            action = Expression( action )
-
-        self.id = id
-        self.title = title
-        self.description = description
-        self.category = category
-        self.condition = condition
-        self.permissions = permissions
-        self.priority = priority
-        self.visible = visible
-        self.setActionExpression(action)
+        self.edit( id
+                 , title
+                 , description
+                 , category
+                 , condition
+                 , permissions
+                 , priority
+                 , visible
+                 , action
+                 )
+        
+    security.declarePrivate('edit')
+    def edit( self
+            , id=_unchanged
+            , title=_unchanged
+            , description=_unchanged
+            , category=_unchanged
+            , condition=_unchanged
+            , permissions=_unchanged
+            , priority=_unchanged
+            , visible=_unchanged
+            , action=_unchanged
+            ):
+        """Edit the specified properties.
+        """
+        
+        if id is not _unchanged:
+            self.id = id
+        if title is not _unchanged:
+            self.title = title
+        if description is not _unchanged:
+            self.description = description
+        if category is not _unchanged:
+            self.category = category
+        if condition is not _unchanged:
+            if condition and isinstance(condition, basestring):
+                condition = Expression(condition)
+            self.condition = condition
+        if permissions is not _unchanged:
+            self.permissions = permissions
+        if priority is not _unchanged:
+            self.priority = priority
+        if visible is not _unchanged:
+            self.visible = visible
+        if action is not _unchanged:
+            if action and isinstance(action, basestring):
+                action = Expression(action)
+            self.setActionExpression(action)
 
     security.declareProtected( View, 'Title' )
     def Title(self):
@@ -132,7 +165,7 @@
         """
         action = self._getActionObject()
         expr = action and action.text or ''
-        if expr and type( expr ) is StringType:
+        if expr and isinstance(expr, basestring):
             if not expr.startswith('python:') and not expr.startswith('string:'):
                 expr = 'string:${object_url}/%s' % expr
                 self.action = Expression( expr )
@@ -140,7 +173,7 @@
 
     security.declarePrivate( 'setActionExpression' )
     def setActionExpression(self, action):
-        if action and type( action ) is StringType:
+        if action and isinstance(action, basestring):
             if not action.startswith('python:')  and not action.startswith('string:'):
                 action = 'string:${object_url}/%s' % action
                 action = Expression( action )


=== Products/CMFCore/ActionProviderBase.py 1.24 => 1.25 ===
--- Products/CMFCore/ActionProviderBase.py:1.24	Thu Apr 29 12:13:16 2004
+++ Products/CMFCore/ActionProviderBase.py	Wed Jun 30 11:40:17 2004
@@ -59,6 +59,24 @@
         """
         return self._actions or ()
 
+    security.declarePrivate('getActionObject')
+    def getActionObject(self, action):
+        """Return the actions object or None if action doesn't exist.
+        """
+        # separate cataegory and id from action
+        sep = action.rfind('/')
+        if sep == -1:
+            raise ValueError('Actions must have the format <category>/<id>.')
+        category, id = action[:sep], action[sep+1:]
+
+        # search for action and return first one found
+        for ai in self.listActions():
+            if id == ai.getId() and category == ai.getCategory():
+                return ai
+        
+        # no action found
+        return None
+
     security.declarePublic('listActionInfos')
     def listActionInfos(self, action_chain=None, object=None,
                         check_visibility=1, check_permissions=1,
@@ -368,6 +386,9 @@
         """ List all the actions defined by a provider.
         """
         return self._actions or ()
+
+    security.declarePrivate('getActionObject')
+    getActionObject = ActionProviderBase.getActionObject
 
     security.declarePublic('listActionInfos')
     def listActionInfos(self, action_chain=None, object=None,



More information about the CMF-checkins mailing list