예제 #1
0
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        actions = []

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.providedBy(provider) or \
                    z2IActionProvider.isImplementedBy(provider):
                actions.extend(provider.listActionInfos(object=object))

        # Include actions from object.
        if object is not None:
            if IActionProvider.providedBy(object) or \
                    z2IActionProvider.isImplementedBy(object):
                actions.extend(object.listActionInfos(object=object))

        # Reorganize the actions by category.
        filtered_actions = {
            'user': [],
            'folder': [],
            'object': [],
            'global': [],
            'workflow': [],
        }

        for action in actions:
            catlist = filtered_actions.setdefault(action['category'], [])
            catlist.append(action)

        return filtered_actions
예제 #2
0
파일: ActionsTool.py 프로젝트: goschtl/zope
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        actions = []

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                actions.extend( provider.listActionInfos(object=object) )

        # Include actions from object.
        if object is not None:
            if IActionProvider.isImplementedBy(object):
                actions.extend( object.listActionInfos(object=object) )

        # Reorganize the actions by category.
        filtered_actions={'user':[],
                          'folder':[],
                          'object':[],
                          'global':[],
                          'workflow':[],
                          }
        for action in actions:
            category = action['category']
            catlist = filtered_actions.get(category, None)
            if catlist is None:
                filtered_actions[category] = catlist = []
            catlist.append(action)
            # ...should you need it, here's some code that filters
            # by equality (use instead of the line above)
            #if not action in catlist:
            #    catlist.append(action)
        return filtered_actions
예제 #3
0
파일: ActionsTool.py 프로젝트: goschtl/zope
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        actions = []

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.providedBy(provider) or \
                    z2IActionProvider.isImplementedBy(provider):
                actions.extend( provider.listActionInfos(object=object) )

        # Include actions from object.
        if object is not None:
            if IActionProvider.providedBy(object) or \
                    z2IActionProvider.isImplementedBy(object):
                actions.extend( object.listActionInfos(object=object) )

        # Reorganize the actions by category.
        filtered_actions={'user':[],
                          'folder':[],
                          'object':[],
                          'global':[],
                          'workflow':[],
                          }

        for action in actions:
            catlist = filtered_actions.setdefault(action['category'], [])
            catlist.append(action)

        return filtered_actions
예제 #4
0
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        actions = []

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                actions.extend(provider.listActionInfos(object=object))

        # Include actions from object.
        if object is not None:
            if IActionProvider.isImplementedBy(object):
                actions.extend(object.listActionInfos(object=object))

        # Reorganize the actions by category.
        filtered_actions = {
            'user': [],
            'folder': [],
            'object': [],
            'global': [],
            'workflow': [],
        }
        for action in actions:
            category = action['category']
            catlist = filtered_actions.get(category, None)
            if catlist is None:
                filtered_actions[category] = catlist = []
            catlist.append(action)
            # ...should you need it, here's some code that filters
            # by equality (use instead of the line above)
            #if not action in catlist:
            #    catlist.append(action)
        return filtered_actions
예제 #5
0
    def _extractOldstyleActions(self, provider_id):
        # BBB: for CMF 1.5 profiles
        fragment = self._doc.createDocumentFragment()

        provider = getToolByName(self.context, provider_id)
        if not IActionProvider.isImplementedBy(provider):
            return fragment

        if provider_id == 'portal_actions':
            actions = provider._actions
        else:
            actions = provider.listActions()

        if actions and isinstance(actions[0], dict):
            return fragment

        for ai in actions:
            mapping = ai.getMapping()
            child = self._doc.createElement('action')
            child.setAttribute('action_id', mapping['id'])
            child.setAttribute('category', mapping['category'])
            child.setAttribute('condition_expr', mapping['condition'])
            child.setAttribute('title', mapping['title'])
            child.setAttribute('url_expr', mapping['action'])
            child.setAttribute('visible', str(mapping['visible']))
            for permission in mapping['permissions']:
                sub = self._doc.createElement('permission')
                sub.appendChild(self._doc.createTextNode(permission))
                child.appendChild(sub)
            fragment.appendChild(child)
        return fragment
예제 #6
0
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        actions = []

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                actions.extend(provider.listActionInfos(object=object))
            else:
                # for Action Providers written for CMF versions before 1.5
                actions.extend(self._listActionInfos(provider, object))

        # Include actions from object.
        if object is not None:
            base = aq_base(object)
            if IActionProvider.isImplementedBy(base):
                actions.extend(object.listActionInfos(object=object))
            elif hasattr(base, 'listActions'):
                # for objects written for CMF versions before 1.5
                actions.extend(self._listActionInfos(object, object))

        # Reorganize the actions by category.
        filtered_actions = {
            'user': [],
            'folder': [],
            'object': [],
            'global': [],
            'workflow': [],
        }

        for action in actions:
            catlist = filtered_actions.setdefault(action['category'], [])
            catlist.append(action)

        return filtered_actions
예제 #7
0
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        actions = []

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                actions.extend( provider.listActionInfos(object=object) )
            else:
                # for Action Providers written for CMF versions before 1.5
                actions.extend( self._listActionInfos(provider, object) )

        # Include actions from object.
        if object is not None:
            base = aq_base(object)
            if IActionProvider.isImplementedBy(base):
                actions.extend( object.listActionInfos(object=object) )
            elif hasattr(base, 'listActions'):
                # for objects written for CMF versions before 1.5
                actions.extend( self._listActionInfos(object, object) )

        # Reorganize the actions by category.
        filtered_actions={'user':[],
                          'folder':[],
                          'object':[],
                          'global':[],
                          'workflow':[],
                          }

        for action in actions:
            catlist = filtered_actions.setdefault(action['category'], [])
            catlist.append(action)

        return filtered_actions
예제 #8
0
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        #cache = None
        #cache_mgr = getToolByName(self, 'portal_actionscache', None)

        #if cache_mgr is not None:
        #    cache = cache_mgr.ZCacheManager_getCache()

        #if cache is not None:
        #    pm = getToolByName(self, 'portal_membership')
        #    if object is None:
        #        object_url = ''
        #    else:
        #        object_url = object.absolute_url()
        #    if pm.isAnonymousUser():
        #        member = None
        #    else:
        #        member = pm.getAuthenticatedMember()
        #    # Prepare a cache key.
        #    keyset = {'object_url': object_url,
        #              'member': member,
        #             }
        #    result = cache.ZCache_get(ob=self, keywords=keyset)
        #    if result is not None:
        #        # Got a cached value.
        #        return result

        actions = []
        ec = getExprContext(self, object)

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                start = time()
                actions.extend(provider.listActionInfos(object=object, ec=ec))
                stop = time()
                open('/tmp/provider_times',
                     'a').write('%-20s: %8.3f\n' % (provider_name,
                                                    (stop - start) * 1000))
            else:
                # for Action Providers written for CMF versions before 1.5
                actions.extend(self._listActionInfos(provider, object))

        # Include actions from object.
        if object is not None:
            base = aq_base(object)
            if IActionProvider.isImplementedBy(base):
                actions.extend(object.listActionInfos(object=object))
            elif hasattr(base, 'listActions'):
                # for objects written for CMF versions before 1.5
                actions.extend(self._listActionInfos(object, object))

        # Reorganize the actions by category.
        filtered_actions = {
            'user': [],
            'folder': [],
            'object': [],
            'global': [],
            'workflow': [],
        }

        for action in actions:
            catlist = filtered_actions.setdefault(action['category'], [])
            catlist.append(action)

        #if cache is not None:
        #    result = cache.ZCache_set(ob=self, data=filtered_actions,
        #                              keywords=keyset)
        return filtered_actions
예제 #9
0
파일: ActionsTool.py 프로젝트: goschtl/zope
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        #cache = None
        #cache_mgr = getToolByName(self, 'portal_actionscache', None)

        #if cache_mgr is not None:
        #    cache = cache_mgr.ZCacheManager_getCache()

        #if cache is not None:
        #    pm = getToolByName(self, 'portal_membership')
        #    if object is None:
        #        object_url = ''
        #    else:
        #        object_url = object.absolute_url()
        #    if pm.isAnonymousUser():
        #        member = None
        #    else:
        #        member = pm.getAuthenticatedMember()
        #    # Prepare a cache key.
        #    keyset = {'object_url': object_url,
        #              'member': member,
        #             }
        #    result = cache.ZCache_get(ob=self, keywords=keyset)
        #    if result is not None:
        #        # Got a cached value.
        #        return result

        actions = []
        ec = getExprContext(self, object)

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                start = time()
                actions.extend( provider.listActionInfos(object=object,
                                                         ec=ec) )
                stop = time()
                open( '/tmp/provider_times', 'a' ).write(
                   '%-20s: %8.3f\n' % (provider_name, (stop-start)*1000) )
            else:
                # for Action Providers written for CMF versions before 1.5
                actions.extend( self._listActionInfos(provider, object) )

        # Include actions from object.
        if object is not None:
            base = aq_base(object)
            if IActionProvider.isImplementedBy(base):
                actions.extend( object.listActionInfos(object=object) )
            elif hasattr(base, 'listActions'):
                # for objects written for CMF versions before 1.5
                actions.extend( self._listActionInfos(object, object) )

        # Reorganize the actions by category.
        filtered_actions={'user':[],
                          'folder':[],
                          'object':[],
                          'global':[],
                          'workflow':[],
                          }

        for action in actions:
            catlist = filtered_actions.setdefault(action['category'], [])
            catlist.append(action)

        #if cache is not None:
        #    result = cache.ZCache_set(ob=self, data=filtered_actions,
        #                              keywords=keyset)
        return filtered_actions