Esempio n. 1
0
        def normalize_actions(category, object, level, parent_url = None):
            """walk through the tabs dictionary and build list of all tabs"""
            tabs = []
            for info in self._actionInfos(category, object):
                icon = info['icon'] and '<img src="%s" />' % info['icon'] or ''
                children = []
                bottomLevel = self.conf.actions_tabs_level
                if bottomLevel < 1 or level < bottomLevel:
                    # try to find out appropriate subcategory
                    subcat_id = self.cat_prefix + info['id'] + self.cat_sufix
                    if subcat_id != info['id'] and \
                       subcat_id in category.objectIds():
                        subcat = category._getOb(subcat_id)
                        if IActionCategory.providedBy(subcat):
                            children = normalize_actions(subcat, object, level+1, info['url'])

                parent_id = category['id'].replace(self.cat_prefix,'').replace(self.cat_sufix,'')
                tab = {'id' : info['id'],
                   'title': info['title'],
                   'url': info['url'],
                   'parent': (parent_id, parent_url)}
                tabslist.append(tab)
                
                tab = {'id' : info['id'],
                       'Title': info['title'],
                       'Description': info['description'],
                       'getURL': info['url'],
                       'show_children': len(children) > 0,
                       'children': children,
                       'currentItem': False, 
                       'currentParent': False,
                       'item_icon': {'html_tag': icon},
                       'normalized_review_state': 'visible'}
                tabs.append(tab)
            return tabs    
Esempio n. 2
0
    def display(self):
        actions = []
        for category in self.portal_actions.objectValues():
            if category.id == 'controlpanel':
                continue
            if not IActionCategory.providedBy(category):
                continue
            cat_infos = {
                'id': category.id,
                'title': category.title or category.id,
            }
            action_list = []
            for action in category.objectValues():
                if IAction.providedBy(action):
                    action_list.append({
                        'id': action.id,
                        'title': action.title,
                        'url': action.absolute_url(),
                        'visible': action.visible,
                    })
            cat_infos['actions'] = action_list
            actions.append(cat_infos)

        self.actions = actions
        return self.template()
Esempio n. 3
0
 def all_categories(self):
     portal_actions = getToolByName(self.context, "portal_actions")
     categories = []
     for id, obj in portal_actions.objectItems():
         if IActionCategory.providedBy(obj):
             categories.append(id)
     return categories
Esempio n. 4
0
 def getOrCreateCategory(self, name):
     """Get or create (if necessary) category"""
     portal_actions = self.portal_actions
     if name not in map(lambda x: x.id,
                        filter(lambda x: IActionCategory.providedBy(x),
                               portal_actions.objectValues())):
         portal_actions._setObject(name, ActionCategory(name))
     return self.getActionCategory(name)
Esempio n. 5
0
    def update(self):
        super(FooterViewlet, self).update()
        self.columns = columns = {}

        context = aq_inner(self.context)
        actions_tool = getToolByName(context, 'portal_actions')

        # check if we got root category for all column links
        if not FOOTER_LINKS_CAT in actions_tool.objectIds():
            return

        # prepare expression context for evaluating TAL expressions
        ec = actions_tool._getExprContext(context)

        # go over root category and collect all sub-categories
        container = actions_tool[FOOTER_LINKS_CAT]
        cat_ids = container.objectIds()
        for cid in ('column1', 'column2', 'column3'):
            # skip not existing categories
            if cid not in cat_ids:
                continue

            cat = container[cid]
            if not IActionCategory.providedBy(cat):
                continue

            # prepare category actions
            actions = []
            for action in cat.objectValues():
                # look only for actions
                if not IAction.providedBy(action):
                    continue

                # create actioninfo object to compile and render TAL expressions
                # and check if action is available in current circumstances
                info = ActionInfo(action, ec)
                if not (info['visible'] and info['allowed'] and
                        info['available']):
                    continue

                # and finally extract all required details from action
                desc = action.getProperty('description', None) or None
                if desc is not None:
                    desc = _(safe_unicode(desc))
                actions.append({
                    'id': info['id'],
                    'title': _(safe_unicode(info['title'])),
                    'desc': _(desc),
                    'url': info['url']
                })

            # finally add category to be rendered as footer column
            columns[cid] = {
                'title': _(safe_unicode(cat.getProperty('title', ''))),
                'actions': tuple(actions)
            }

        self.columns = columns
 def getOrCreateCategory(self, name):
     """Get or create (if necessary) category"""
     portal_actions = self.portal_actions
     if name not in map(
             lambda x: x.id,
             filter(lambda x: IActionCategory.providedBy(x),
                    portal_actions.objectValues())):
         portal_actions._setObject(name, ActionCategory(name))
     return self.getActionCategory(name)
Esempio n. 7
0
 def removeActionFromTool(self, action_id, category=None, action_provider='portal_actions'):
     # Removes an action from portal_actions
     tool = getToolByName(self.portal, action_provider)
     if category is None:
         if action_id in tool.objectIds() and IActionInfo.providedBy(tool._getOb(action_id)):
             tool._delOb(action_id)
     else:
         if category in tool.objectIds() and IActionCategory.providedBy(tool._getOb(category)):
             if action_id in tool.objectIds() and IActionInfo.providedBy(tool._getOb(action_id)):
                 tool._delOb(action_id)
Esempio n. 8
0
    def listActions(self):
        """ List the actions defined in this category and its subcategories.
        """
        actions = []

        for obj in self.objectValues():
            if IActionCategory.providedBy(obj):
                actions.extend( obj.listActions() )
            elif IAction.providedBy(obj):
                actions.append(obj)

        return tuple(actions)
Esempio n. 9
0
 def removeActionFromTool(self,
                          action_id,
                          category=None,
                          action_provider='portal_actions'):
     # Removes an action from portal_actions
     tool = getToolByName(self.portal, action_provider)
     if category is None:
         if action_id in tool.objectIds() and \
            IActionInfo.providedBy(tool._getOb(action_id)):
             tool._delOb(action_id)
     elif (category in tool.objectIds()
           and IActionCategory.providedBy(tool._getOb(category))
           and action_id in tool.objectIds()
           and IActionInfo.providedBy(tool._getOb(action_id))):
         tool._delOb(action_id)
Esempio n. 10
0
        def normalize_actions(category, object, level, parent_url=None):
            """walk through the tabs dictionary and build list of all tabs"""
            tabs = []
            for info in self._actionInfos(category, object):
                icon = info['icon'] and '<img src="%s" />' % info['icon'] or ''
                children = []
                bottomLevel = self.conf.actions_tabs_level
                if bottomLevel < 1 or level < bottomLevel:
                    # try to find out appropriate subcategory
                    subcat_id = self.cat_prefix + info['id'] + self.cat_sufix
                    in_category = subcat_id in category.objectIds()
                    if subcat_id != info['id'] and in_category:
                        subcat = category._getOb(subcat_id)
                        if IActionCategory.providedBy(subcat):
                            children = normalize_actions(
                                subcat, object, level + 1, info['url'])

                parent_id = category.getId()
                parent_id = parent_id.replace(self.cat_prefix, '')
                parent_id = parent_id.replace(self.cat_sufix, '')
                tab = {
                    'id': info['id'],
                    'title': info['title'],
                    'url': info['url'],
                    'parent': (parent_id, parent_url)
                }
                tabslist.append(tab)

                tab = {
                    'id': info['id'],
                    'Title': info['title'],
                    'Description': info['description'],
                    'getURL': info['url'],
                    'show_children': len(children) > 0,
                    'children': children,
                    'currentItem': False,
                    'currentParent': False,
                    'item_icon': {
                        'html_tag': icon
                    },
                    'normalized_review_state': 'visible'
                }
                tabs.append(tab)
            return tabs
Esempio n. 11
0
    def listActions(self, info=None, object=None,
                    categories=None, ignore_categories=None):
        """ List all the actions defined by a provider.
        """
        actions = list(self._actions)

        if ignore_categories is None:
            ignore_categories = ()

        if categories is None:
            categories = [cat for cat in self
                          if cat not in ignore_categories]
        else:
            categories = [cat for cat in self
                          if cat in categories]

        for category in categories:
            if IActionCategory.providedBy(self[category]):
                actions.extend(self[category].listActions())
        return tuple(actions)
Esempio n. 12
0
    def listActions(self, info=None, object=None,
                    categories=None, ignore_categories=None):
        """ List all the actions defined by a provider.
        """
        actions = list(self._actions)

        if ignore_categories is None:
            ignore_categories = ()

        if categories is None:
            categories = [cat for cat in self
                              if cat not in ignore_categories]
        else:
            categories = [cat for cat in self
                              if cat in categories]

        for category in categories:
            if IActionCategory.providedBy(self[category]):
                actions.extend(self[category].listActions())
        return tuple(actions)