|
|
Choosing A Webhost: |
CVS: Products/CMFCore - ActionInformation.py:1.26.10.1 ActionsTool.py:1.54.: msg#00039web.zope.cmf.cvs
Update of /cvs-repository/Products/CMFCore In directory cvs.zope.org:/tmp/cvs-serv30226/CMFCore Modified Files: Tag: yuppie-new_actions-branch ActionInformation.py ActionsTool.py __init__.py Log Message: - initial checkin of newstyle Actions === Products/CMFCore/ActionInformation.py 1.26 => 1.26.10.1 === --- Products/CMFCore/ActionInformation.py:1.26 Thu Aug 12 11:07:39 2004 +++ Products/CMFCore/ActionInformation.py Mon Jan 24 14:31:15 2005 @@ -20,17 +20,152 @@ from AccessControl import ClassSecurityInfo from Acquisition import aq_base, aq_inner, aq_parent from Globals import InitializeClass +from OFS.ObjectManager import IFAwareObjectManager +from OFS.OrderedFolder import OrderedFolder from OFS.SimpleItem import SimpleItem +from Products.PageTemplates.PageTemplateFile import PageTemplateFile -from interfaces.portal_actions import ActionInfo as IActionInfo 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 ActionInfo as IActionInfo from permissions import View from utils import _checkPermission +from utils import _wwwdir from utils import getToolByName +from utils import SimpleItemWithProperties _unchanged = [] # marker +class ActionCategory(IFAwareObjectManager, OrderedFolder): + """ Group of Action objects. + """ + + __implements__ = (IActionCategory, OrderedFolder.__implements__) + + meta_type = 'CMF Action Category' + + _product_interfaces = (IActionCategory, IAction) + + security = ClassSecurityInfo() + + security.declarePrivate('listActions') + def listActions(self): + """ List the actions defined in this category and its subcategories. + """ + actions = [] + + for obj in self.objectValues(): + if IActionCategory.isImplementedBy(obj): + actions.extend( obj.listActions() ) + elif IAction.isImplementedBy(obj): + actions.append(obj) + + return tuple(actions) + +InitializeClass(ActionCategory) + +manage_addActionCategoryForm = PageTemplateFile('addActionCategory.zpt', + _wwwdir) + +def manage_addActionCategory(self, id, REQUEST=None): + """Add a new CMF Action Category object with ID *id*. + """ + obj = ActionCategory(id) + self._setObject(id, obj) + + if REQUEST: + return self.manage_main(self, REQUEST, update_menu=1) + + +class Action(SimpleItemWithProperties): + """ Reference to an action. + """ + + __implements__ = IAction + + meta_type = 'CMF Action' + + security = ClassSecurityInfo() + + _properties = ( + {'id': 'title', 'type': 'string', 'mode': 'w', + 'label': 'Title'}, + {'id': 'description', 'type': 'text', 'mode': 'w', + 'label': 'Description'}, + {'id': 'url_expr', 'type': 'string', 'mode': 'w', + 'label': 'URL (Expression)'}, + {'id': 'icon_expr', 'type': 'string', 'mode': 'w', + 'label': 'Icon (Expression)'}, + {'id': 'available_expr', 'type': 'string', 'mode': 'w', + 'label': 'Condition (Expression)'}, + {'id': 'permissions', 'type': 'multiple selection', 'mode': 'w', + 'label': 'Permissions', 'select_variable': 'possible_permissions'}, + {'id': 'visible', 'type': 'boolean', 'mode': 'w', + 'label': 'Visible?'}, + ) + + def __init__(self, id, **kw): + self.id = id + self._setPropValue( 'title', kw.get('title', '') ) + self._setPropValue( 'description', kw.get('description', '') ) + self._setPropValue( 'url_expr', kw.get('url_expr', '') ) + self._setPropValue( 'icon_expr', kw.get('icon_expr', '') ) + self._setPropValue( 'available_expr', kw.get('available_expr', '') ) + self._setPropValue( 'permissions', kw.get('permissions', () ) ) + self._setPropValue( 'visible', kw.get('visible', True) ) + + def _setPropValue(self, id, value): + self._wrapperCheck(value) + if isinstance(value, list): + value = tuple(value) + setattr(self, id, value) + if id.endswith('_expr'): + setattr( self, '%s_object' % id, Expression(value) ) + + security.declarePrivate('getInfoData') + def getInfoData(self): + """ Get the data needed to create an ActionInfo. + """ + category_path = [] + lazy_keys = [] + lazy_map = {} + + lazy_map['id'] = self.getId() + + parent = aq_parent(self) + while parent is not None and parent.getId() != 'portal_actions': + category_path.append( parent.getId() ) + parent = aq_parent(parent) + lazy_map['category'] = '/'.join(category_path[::-1]) + + for id, val in self.propertyItems(): + if id.endswith('_expr'): + id = id[:-5] + if val: + val = getattr(self, '%s_expr_object' % id) + lazy_keys.append(id) + elif id == 'available': + val = True + lazy_map[id] = val + + return (lazy_map, lazy_keys) + +InitializeClass(Action) + +manage_addActionForm = PageTemplateFile( 'addAction.zpt', _wwwdir) + +def manage_addAction(self, id, REQUEST=None): + """Add a new CMF Action object with ID *id*. + """ + obj = Action(id) + self._setObject(id, obj) + + if REQUEST: + return self.manage_main(self, REQUEST) + + class ActionInfo(UserDict): """ A lazy dictionary for Action infos. """ @@ -40,7 +175,12 @@ def __init__(self, action, ec): lazy_keys = [] - if isinstance(action, dict): + if IAction.isImplementedBy(action): + self._ec = ec + (lazy_map, lazy_keys) = action.getInfoData() + UserDict.__init__(self, lazy_map) + + elif isinstance(action, dict): UserDict.__init__(self, action) self.data.setdefault( 'id', self.data['name'].lower() ) self.data.setdefault( 'title', self.data['name'] ) @@ -82,7 +222,7 @@ def __getitem__(self, key): value = UserDict.__getitem__(self, key) if key in self._lazy_keys: - value = self.data[key] = value() + value = self.data[key] = value(self._ec) self._lazy_keys.remove(key) return value @@ -98,30 +238,30 @@ else: return self.data == other - def _getURL(self): + def _getURL(self, ec): """ Get the result of the URL expression in the current context. """ - return self._action._getActionObject()(self._ec) + return self._action._getActionObject()(ec) - def _checkCondition(self): + def _checkCondition(self, ec): """ Check condition expression in the current context. """ - return self._action.testCondition(self._ec) + return self._action.testCondition(ec) - def _checkPermissions(self): + def _checkPermissions(self, ec): """ Check permissions in the current context. """ category = self['category'] - object = self._ec.contexts['object'] + object = ec.contexts['object'] if object is not None and ( category.startswith('object') or category.startswith('workflow') ): context = object else: - folder = self._ec.contexts['folder'] + folder = ec.contexts['folder'] if folder is not None and category.startswith('folder'): context = folder else: - context = self._ec.contexts['portal'] + context = ec.contexts['portal'] for permission in self['permissions']: if _checkPermission(permission, context): === Products/CMFCore/ActionsTool.py 1.54 => 1.54.2.1 === --- Products/CMFCore/ActionsTool.py:1.54 Tue Sep 14 15:02:21 2004 +++ Products/CMFCore/ActionsTool.py Mon Jan 24 14:31:15 2005 @@ -18,30 +18,35 @@ from AccessControl import ClassSecurityInfo from Globals import DTMLFile from Globals import InitializeClass -from OFS.Folder import Folder +from OFS.ObjectManager import IFAwareObjectManager +from OFS.OrderedFolder import OrderedFolder 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 from permissions import ListFolderContents from permissions import ManagePortal from utils import _dtmldir -from utils import SimpleItemWithProperties from utils import UniqueObject -class ActionsTool(UniqueObject, Folder, ActionProviderBase): +class ActionsTool(UniqueObject, IFAwareObjectManager, OrderedFolder, + ActionProviderBase): """ Weave together the various sources of "actions" which are apropos to the current user and context. """ - __implements__ = (IActionsTool, ActionProviderBase.__implements__) + __implements__ = (IActionsTool, OrderedFolder.__implements__, + ActionProviderBase.__implements__) id = 'portal_actions' meta_type = 'CMF Actions Tool' + _product_interfaces = (IActionCategory,) _actions = (ActionInformation(id='folderContents' , title='Folder contents' , action=Expression( @@ -68,15 +73,13 @@ security = ClassSecurityInfo() - manage_options = ( ActionProviderBase.manage_options - + ( { 'label' : 'Action Providers' - , 'action' : 'manage_actionProviders' - } - , { 'label' : 'Overview' - , 'action' : 'manage_overview' - } - ) + Folder.manage_options - ) + manage_options = ( ( OrderedFolder.manage_options[0], + ActionProviderBase.manage_options[0], + {'label': 'Action Providers', + 'action': 'manage_actionProviders'}, + {'label': 'Overview', + 'action': 'manage_overview'} ) + + OrderedFolder.manage_options[2:] ) # # ZMI methods @@ -108,6 +111,34 @@ if REQUEST is not None: return self.manage_actionProviders(self , REQUEST , manage_tabs_message='Providers changed.') + + security.declareProtected( ManagePortal, 'manage_editActionsForm' ) + def manage_editActionsForm( self, REQUEST, manage_tabs_message=None ): + """ Show the 'Actions' management tab. + """ + actions = [ ai.getMapping() for ai in self._actions ] + + # possible_permissions is in AccessControl.Role.RoleManager. + pp = self.possible_permissions() + return self._actions_form( self + , REQUEST + , actions=actions + , possible_permissions=pp + , management_view='Actions' + , manage_tabs_message=manage_tabs_message + ) + + # + # ActionProvider interface + # + security.declarePrivate('listActions') + def listActions(self, info=None, object=None): + """ List all the actions defined by a provider. + """ + actions = list(self._actions) + for category in self.objectValues(): + actions.extend( category.listActions() ) + return tuple(actions) # # Programmatically manipulate the list of action providers === Products/CMFCore/__init__.py 1.30 => 1.30.2.1 === --- Products/CMFCore/__init__.py:1.30 Sun Nov 28 16:40:27 2004 +++ Products/CMFCore/__init__.py Mon Jan 24 14:31:15 2005 @@ -26,6 +26,7 @@ import FSDTMLMethod, FSPythonScript, FSSTXMethod import FSPageTemplate import FSZSQLMethod +import ActionInformation import CookieCrumbler import ContentTypeRegistry import CachingPolicyManager @@ -99,6 +100,22 @@ constructors=( CachingPolicyManager.manage_addCachingPolicyManager, ), icon = 'images/registry.gif' ) + + context.registerClass( + ActionInformation.ActionCategory, + permission=ManagePortal, + constructors=(ActionInformation.manage_addActionCategoryForm, + ActionInformation.manage_addActionCategory), + icon='images/cmf_action_category.gif', + visibility=None) + + context.registerClass( + ActionInformation.Action, + permission=ManagePortal, + constructors=(ActionInformation.manage_addActionForm, + ActionInformation.manage_addAction), + icon='images/cmf_action.gif', + visibility=None) context.registerClass( TypesTool.FactoryTypeInformation,
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | CVS: Products/CMFCore/www - addAction.zpt:1.1.2.1 addActionCategory.zpt:1.1.2.1, Yvo Schubbe |
|---|---|
| Next by Date: | CVS: Products/CMFCore/interfaces - portal_actions.py:1.19.2.1, Yvo Schubbe |
| Previous by Thread: | CVS: Products/CMFCore/www - addAction.zpt:1.1.2.1 addActionCategory.zpt:1.1.2.1, Yvo Schubbe |
| Next by Thread: | CVS: Products/CMFCore/interfaces - portal_actions.py:1.19.2.1, Yvo Schubbe |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |