Beispiel #1
0
    def getActionById( self, id, default=_marker ):
        """ Get method ID by action ID.
        """
        warn('getActionById() is deprecated and will be removed in CMF 2.0. '
             'Please use getActionInfo()[\'url\'] if you need an URL or '
             'queryMethodID() if you need a method ID.',
             DeprecationWarning)
        context = getActionContext( self )
        for action in self.listActions():

            __traceback_info__ = (self.getId(), action)

            if action.getId() == id:
                target = action.action(context).strip()
                if target.startswith('/'):
                    target = target[1:]
                return target
            else:
                # Temporary backward compatibility.
                if action.Title().lower() == id:
                    target = action.action(context).strip()
                    if target.startswith('/'):
                        target = target[1:]
                    return target

        if default is _marker:
            raise ValueError, ('No action "%s" for type "%s"'
                               % (id, self.getId()))
        else:
            return default
Beispiel #2
0
    def getActionById(self, id, default=_marker):
        """
            Return the URL of the action whose ID is id.
        """
        context = getActionContext(self)
        for action in self.listActions():

            __traceback_info__ = (self.getId(), action)

            if action.getId() == id:
                target = action.action(context).strip()
                if target.startswith('/'):
                    target = target[1:]
                return target
            else:
                # Temporary backward compatibility.
                if action.Title().lower() == id:
                    target = action.action(context).strip()
                    if target.startswith('/'):
                        target = target[1:]
                    return target

        if default is _marker:
            raise ValueError, ('No action "%s" for type "%s"' %
                               (id, self.getId()))
        else:
            return default
Beispiel #3
0
    def getActionById(self, id, default=_marker):
        """ Get method ID by action ID.
        """
        warn(
            'getActionById() is deprecated and will be removed in CMF 1.6. '
            'Please use getActionInfo()[\'url\'] if you need an URL or '
            'queryMethodID() if you need a method ID.', DeprecationWarning)
        context = getActionContext(self)
        for action in self.listActions():

            __traceback_info__ = (self.getId(), action)

            if action.getId() == id:
                target = action.action(context).strip()
                if target.startswith('/'):
                    target = target[1:]
                return target
            else:
                # Temporary backward compatibility.
                if action.Title().lower() == id:
                    target = action.action(context).strip()
                    if target.startswith('/'):
                        target = target[1:]
                    return target

        if default is _marker:
            raise ValueError, ('No action "%s" for type "%s"' %
                               (id, self.getId()))
        else:
            return default
Beispiel #4
0
    def getActionById( self, id, default=_marker ):
        """
            Return the URL of the action whose ID is id.
        """
        context = getActionContext( self )
        for action in self.listActions():

            __traceback_info__ = (self.getId(), action)

            if action.getId() == id:
                target = action.action(context).strip()
                if target.startswith('/'):
                    target = target[1:]
                return target
            else:
                # Temporary backward compatibility.
                if action.Title().lower() == id:
                    target = action.action(context).strip()
                    if target.startswith('/'):
                        target = target[1:]
                    return target

        if default is _marker:
            raise ValueError, ('No action "%s" for type "%s"'
                               % (id, self.getId()))
        else:
            return default
Beispiel #5
0
    def _guessMethodAliases(self):
        """ Guess and set Method Aliases. Used for upgrading old TIs.
        """
        context = getActionContext(self)
        actions = self.listActions()
        ordered = []
        _dict = {}
        viewmethod = ''

        # order actions and search 'mkdir' action
        for action in actions:
            if action.getId() == 'view':
                ordered.insert(0, action)
            elif action.getId() == 'mkdir':
                try:
                    mkdirmethod = action.action(context).strip()
                except AttributeError:
                    continue
                if mkdirmethod.startswith('/'):
                    mkdirmethod = mkdirmethod[1:]
                _dict['mkdir'] = mkdirmethod
            else:
                ordered.append(action)

        # search 'view' action
        for action in ordered:
            perms = action.getPermissions()
            if not perms or View in perms:
                try:
                    viewmethod = action.action(context).strip()
                except AttributeError, TypeError:
                    break
                if viewmethod.startswith('/'):
                    viewmethod = viewmethod[1:]
                if not viewmethod:
                    viewmethod = '(Default)'
                break
Beispiel #6
0
    def _guessMethodAliases(self):
        """ Guess and set Method Aliases. Used for upgrading old TIs.
        """
        context = getActionContext(self)
        actions = self.listActions()
        ordered = []
        _dict = {}
        viewmethod = ''

        # order actions and search 'mkdir' action
        for action in actions:
            if action.getId() == 'view':
                ordered.insert(0, action)
            elif action.getId() == 'mkdir':
                try:
                    mkdirmethod = action.action(context).strip()
                except AttributeError:
                    continue
                if mkdirmethod.startswith('/'):
                    mkdirmethod = mkdirmethod[1:]
                _dict['mkdir'] = mkdirmethod
            else:
                ordered.append(action)

        # search 'view' action
        for action in ordered:
            perms = action.getPermissions()
            if not perms or View in perms:
                try:
                    viewmethod = action.action(context).strip()
                except (AttributeError, TypeError):
                    break
                if viewmethod.startswith('/'):
                    viewmethod = viewmethod[1:]
                if not viewmethod:
                    viewmethod = '(Default)'
                break
        else:
            viewmethod = '(Default)'
        if viewmethod:
            _dict['view'] = viewmethod

        # search default action
        for action in ordered:
            try:
                defmethod = action.action(context).strip()
            except (AttributeError, TypeError):
                break
            if defmethod.startswith('/'):
                defmethod = defmethod[1:]
            if not defmethod:
                break
        else:
            if viewmethod:
                _dict['(Default)'] = viewmethod

        # correct guessed values if we know better
        if self.content_meta_type in ('Portal File', 'Portal Folder',
                                      'Portal Image'):
            _dict['(Default)'] = 'index_html'
            if viewmethod == '(Default)':
                _dict['view'] = 'index_html'
        if self.content_meta_type in ('Document', 'News Item'):
            _dict['gethtml'] = 'source_html'

        self.setMethodAliases(_dict)
        return 1
Beispiel #7
0
    def _guessMethodAliases(self):
        """ Guess and set Method Aliases. Used for upgrading old TIs.
        """
        context = getActionContext(self)
        actions = self.listActions()
        ordered = []
        _dict = {}
        viewmethod = ''

        # order actions and search 'mkdir' action
        for action in actions:
            if action.getId() == 'view':
                ordered.insert(0, action)
            elif action.getId() == 'mkdir':
                try:
                    mkdirmethod = action.action(context).strip()
                except AttributeError:
                    continue
                if mkdirmethod.startswith('/'):
                    mkdirmethod = mkdirmethod[1:]
                _dict['mkdir'] = mkdirmethod
            else:
                ordered.append(action)

        # search 'view' action
        for action in ordered:
            perms = action.getPermissions()
            if not perms or View in perms:
                try:
                    viewmethod = action.action(context).strip()
                except AttributeError:
                    break
                if viewmethod.startswith('/'):
                    viewmethod = viewmethod[1:]
                if not viewmethod:
                    viewmethod = '(Default)'
                break
        else:
            viewmethod = '(Default)'
        if viewmethod:
            _dict['view'] = viewmethod

        # search default action
        for action in ordered:
            try:
                defmethod = action.action(context).strip()
            except AttributeError:
                break
            if defmethod.startswith('/'):
                defmethod = defmethod[1:]
            if not defmethod:
                break
        else:
            if viewmethod:
                _dict['(Default)'] = viewmethod

        # correct guessed values if we know better
        if self.content_meta_type in ('Portal File', 'Portal Folder',
                                      'Portal Image'):
            _dict['(Default)'] = 'index_html'
            if viewmethod == '(Default)':
                _dict['view'] = 'index_html'
        if self.content_meta_type in ('Document', 'News Item'):
            _dict['gethtml'] = 'source_html'

        self.setMethodAliases(_dict)
        return 1