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()
def listActions(self, info=None, object=None): """ List all the actions defined by a provider. """ oldstyle_actions = self._actions or () if oldstyle_actions: warn( 'Old-style actions are deprecated and will be removed in CMF ' '2.4. Use Action and Action Category objects instead.', DeprecationWarning, stacklevel=2) actions = list(oldstyle_actions) if object is None and info is not None: object = info.object if object is not None: type_info = self.getTypeInfo(object) if type_info is not None: actions.extend(type_info.listActions(info, object)) add_actions = [ ti for ti in self.objectValues() if IAction.providedBy(ti) ] actions.extend(add_actions) return actions
def _actionInfos(self, category, object, check_visibility=1, check_permissions=1, check_condition=1, max=-1): """Return action infos for a given category""" ec = self.tool._getExprContext(object) actions = [ ActionInfo(action, ec) for action in category.objectValues() if IAction.providedBy(action) ] action_infos = [] for ai in actions: if check_visibility and not ai['visible']: continue if check_permissions and not ai['allowed']: continue if check_condition and not ai['available']: continue action_infos.append(ai) if max + 1 and len(action_infos) >= max: break return action_infos
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 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)
def getPortalActions(self, category="portal_tabs"): """See interface""" portal_actions = self.portal_actions if category not in portal_actions.objectIds(): return [] actions = [] for item in portal_actions[category].objectValues(): if IAction.providedBy(item): actions.append(item) return actions
def _actionInfos(self, category, object, check_visibility=1, check_permissions=1, check_condition=1, max=-1): """Return action infos for a given category""" ec = self.tool._getExprContext(object) actions = [ActionInfo(action, ec) for action in category.objectValues() if IAction.providedBy(action)] action_infos = [] for ai in actions: if check_visibility and not ai['visible']: continue if check_permissions and not ai['allowed']: continue if check_condition and not ai['available']: continue action_infos.append(ai) if max + 1 and len(action_infos) >= max: break return action_infos
def listActions(self, info=None, object=None, category=None): # List all the actions defined by a provider. actions = [] if object is None and info is not None: object = info.object if object is not None: type_info = self.getTypeInfo(object) if type_info is not None: type_actions = type_info.listActions(info, object) if category is not None: type_actions = [a for a in type_actions if a.category == category] actions.extend(type_actions) if category == 'folder/add': add_actions = [ti for ti in self.values() if IAction.providedBy(ti)] actions.extend(add_actions) return actions
def listActions(self, info=None, object=None): """ List all the actions defined by a provider. """ oldstyle_actions = self._actions or () if oldstyle_actions: warn('Old-style actions are deprecated and will be removed in CMF ' '2.4. Use Action and Action Category objects instead.', DeprecationWarning, stacklevel=2) actions = list(oldstyle_actions) if object is None and info is not None: object = info.object if object is not None: type_info = self.getTypeInfo(object) if type_info is not None: actions.extend( type_info.listActions(info, object) ) add_actions = [ ti for ti in self.objectValues() if IAction.providedBy(ti) ] actions.extend(add_actions) return actions
def get_items(self): items = [] for item in get_category().objectValues(): if IAction.providedBy(item): items.append(item) return items