[CMF-checkins] CVS: Products/CMFCore -
ActionInformation.py:1.22.2.1 ActionProviderBase.py:1.27.2.1
TypesTool.py:1.70.4.1
Yvo Schubbe
y.2004_ at wcm-solutions.de
Sun Jul 18 17:55:48 EDT 2004
Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv15484/CMFCore
Modified Files:
Tag: yuppie-actions-cleanup-branch
ActionInformation.py ActionProviderBase.py TypesTool.py
Log Message:
- added 'getMapping' method to replace some redundant code
- Action 'title' is an alias of 'name'
- Action 'visible' is a boolean
- some related cleanup
=== Products/CMFCore/ActionInformation.py 1.22 => 1.22.2.1 ===
--- Products/CMFCore/ActionInformation.py:1.22 Fri Jul 16 12:49:21 2004
+++ Products/CMFCore/ActionInformation.py Sun Jul 18 17:55:17 2004
@@ -16,8 +16,8 @@
"""
from AccessControl import ClassSecurityInfo
-from Globals import InitializeClass
from Acquisition import aq_base, aq_inner, aq_parent
+from Globals import InitializeClass
from OFS.SimpleItem import SimpleItem
from Expression import Expression
@@ -47,7 +47,7 @@
, condition=''
, permissions=()
, priority=10
- , visible=1
+ , visible=True
, action=''
):
""" Set up an instance.
@@ -62,7 +62,7 @@
, visible
, action
)
-
+
security.declarePrivate('edit')
def edit( self
, id=_unchanged
@@ -77,7 +77,7 @@
):
"""Edit the specified properties.
"""
-
+
if id is not _unchanged:
self.id = id
if title is not _unchanged:
@@ -135,7 +135,7 @@
"""
info = {}
info['id'] = self.id
- info['name'] = self.Title()
+ info['title'] = info['name'] = self.Title()
expr = self.getActionExpression()
__traceback_info__ = (info['id'], info['name'], expr)
action_obj = self._getActionObject()
@@ -209,23 +209,26 @@
""" Return whether the action should be visible in the CMF UI.
"""
- return self.visible
+ return bool(self.visible)
- security.declarePrivate( 'clone' )
- def clone( self ):
+ security.declarePrivate('getMapping')
+ def getMapping(self):
+ """ Get a mapping of this object's data.
+ """
+ return { 'id': self.getId(),
+ 'title': self.Title(),
+ 'description': self.Description(),
+ 'category': self.getCategory(),
+ 'condition': self.getCondition(),
+ 'permissions': self.getPermissions(),
+ 'visible': self.getVisibility(),
+ 'action': self.getActionExpression() }
- """ Return a newly-created AI just like us.
+ security.declarePrivate('clone')
+ def clone( self ):
+ """ Get a newly-created AI just like us.
"""
- return self.__class__( id=self.id
- , title=self.title
- , description=self.description
- , category =self.category
- , condition=self.getCondition()
- , permissions=self.permissions
- , priority =self.priority
- , visible=self.visible
- , action=self.getActionExpression()
- )
+ return self.__class__( priority=self.priority, **self.getMapping() )
InitializeClass( ActionInformation )
=== Products/CMFCore/ActionProviderBase.py 1.27 => 1.27.2.1 ===
--- Products/CMFCore/ActionProviderBase.py:1.27 Fri Jul 16 12:49:21 2004
+++ Products/CMFCore/ActionProviderBase.py Sun Jul 18 17:55:17 2004
@@ -15,19 +15,18 @@
$Id$
"""
-from types import StringType
-
-from Globals import DTMLFile, InitializeClass
from AccessControl import ClassSecurityInfo
+from Globals import DTMLFile
+from Globals import InitializeClass
from ActionInformation import ActionInformation
from ActionInformation import getOAI
-from permissions import ManagePortal
from Expression import Expression
from Expression import getExprContext
from interfaces.portal_actions import ActionProvider as IActionProvider
from interfaces.portal_actions \
import OldstyleActionProvider as IOldstyleActionProvider
+from permissions import ManagePortal
from utils import _checkPermission
from utils import _dtmldir
@@ -73,7 +72,7 @@
for ai in self.listActions():
if id == ai.getId() and category == ai.getCategory():
return ai
-
+
# no action found
return None
@@ -89,7 +88,7 @@
if action_chain:
filtered_actions = []
- if isinstance(action_chain, StringType):
+ if isinstance(action_chain, basestring):
action_chain = (action_chain,)
for action_ident in action_chain:
sep = action_ident.rfind('/')
@@ -149,23 +148,7 @@
""" Show the 'Actions' management tab.
"""
- actions = []
-
- for a in self.listActions():
-
- a1 = {}
- a1['id'] = a.getId()
- a1['name'] = a.Title()
- p = a.getPermissions()
- if p:
- a1['permission'] = p[0]
- else:
- a1['permission'] = ''
- a1['category'] = a.getCategory() or 'object'
- a1['visible'] = a.getVisibility()
- a1['action'] = a.getActionExpression()
- a1['condition'] = a.getCondition()
- actions.append(a1)
+ actions = [ ai.getMapping() for ai in self.listActions() ]
# possible_permissions is in AccessControl.Role.RoleManager.
pp = self.possible_permissions()
@@ -196,7 +179,7 @@
a_expr = action and Expression(text=str(action)) or ''
c_expr = condition and Expression(text=str(condition)) or ''
- if type( permission ) != type( () ):
+ if not isinstance(permission, tuple):
permission = (str(permission),)
new_actions = self._cloneActions()
@@ -328,36 +311,24 @@
""" Extract an ActionInformation from the funky form properties.
"""
id = str( properties.get( 'id_%d' % index, '' ) )
- name = str( properties.get( 'name_%d' % index, '' ) )
+ title = str( properties.get( 'name_%d' % index, '' ) )
action = str( properties.get( 'action_%d' % index, '' ) )
condition = str( properties.get( 'condition_%d' % index, '' ) )
category = str( properties.get( 'category_%d' % index, '' ))
- visible = properties.get( 'visible_%d' % index, 0 )
+ visible = bool( properties.get('visible_%d' % index, False) )
permissions = properties.get( 'permission_%d' % index, () )
- if not name:
- raise ValueError('A name is required.')
-
- if action is not '':
- action = Expression( text=action )
-
- if condition is not '':
- condition = Expression( text=condition )
+ if not title:
+ raise ValueError('A title is required.')
if category == '':
category = 'object'
- if type( visible ) is not type( 0 ):
- try:
- visible = int( visible )
- except:
- visible = 0
-
- if type( permissions ) is type( '' ):
+ if isinstance(permissions, basestring):
permissions = ( permissions, )
return ActionInformation( id=id
- , title=name
+ , title=title
, action=action
, condition=condition
, permissions=permissions
@@ -402,7 +373,7 @@
if action_chain:
filtered_actions = []
- if isinstance(action_chain, StringType):
+ if isinstance(action_chain, basestring):
action_chain = (action_chain,)
for action_ident in action_chain:
sep = action_ident.rfind('/')
=== Products/CMFCore/TypesTool.py 1.70 => 1.70.4.1 ===
--- Products/CMFCore/TypesTool.py:1.70 Wed Jul 7 11:53:14 2004
+++ Products/CMFCore/TypesTool.py Sun Jul 18 17:55:17 2004
@@ -301,11 +301,11 @@
for action in aa:
# Some backward compatibility stuff.
- if not action.has_key('id'):
+ if not 'id' in action:
action['id'] = cookString(action['name'])
- if not action.has_key('name'):
- action['name'] = action['id'].capitalize()
+ if not 'title' in action:
+ action['title'] = action.get('name', action['id'].capitalize())
# historically, action['action'] is simple string
actiontext = action.get('action').strip() or 'string:${object_url}'
@@ -314,12 +314,12 @@
self.addAction(
id=action['id']
- , name=action['name']
+ , name=action['title']
, action=actiontext
, condition=action.get('condition')
, permission=action.get( 'permissions', () )
, category=action.get('category', 'object')
- , visible=action.get('visible', 1)
+ , visible=action.get('visible', True)
)
security.declarePublic('constructInstance')
@@ -430,7 +430,7 @@
if not perms or View in perms:
try:
viewmethod = action.action(context).strip()
- except AttributeError:
+ except AttributeError, TypeError:
break
if viewmethod.startswith('/'):
viewmethod = viewmethod[1:]
@@ -446,7 +446,7 @@
for action in ordered:
try:
defmethod = action.action(context).strip()
- except AttributeError:
+ except AttributeError, TypeError:
break
if defmethod.startswith('/'):
defmethod = defmethod[1:]
More information about the CMF-checkins
mailing list