def to_display_list(pairs, sort_by="key", allow_empty=True): """Create a Plone DisplayList from list items :param pairs: list of key, value pairs :param sort_by: Sort the items either by key or value :param allow_empty: Allow to select an empty value :returns: Plone DisplayList """ dl = DisplayList() if isinstance(pairs, basestring): pairs = [pairs, pairs] for pair in pairs: # pairs is a list of lists -> add each pair if isinstance(pair, (tuple, list)): dl.add(*pair) # pairs is just a single pair -> add it and stop if isinstance(pair, basestring): dl.add(*pairs) break # add the empty option if allow_empty: dl.add("", "") # sort by key/value if sort_by == "key": dl = dl.sortedByKey() elif sort_by == "value": dl = dl.sortedByValue() return dl
def getWfTransitionsDisplayList(self, wfName=config.ECA_WORKFLOW_ID): """ @return a DisplayList containing all transition keys and titles in assignment's workflow """ dl = DisplayList(()) #wtool = self.portal_workflow #wf = wtool.getWorkflowById(wfName) for transition in self.getWfTransitions(): # FIXME: not sure if this works with the result # from getWfTransitions dl.add(transition.id, transition.actbox_name) return dl.sortedByValue()
def getWfTransitionsDisplayList(self, wfName=config.ECA_WORKFLOW_ID): """ @return a DisplayList containing all transition keys and titles in assignment's workflow """ dl = DisplayList(()) #wtool = self.portal_workflow #wf = wtool.getWorkflowById(wfName) for transition in self.getWfTransitions(): # FIXME: not sure if this works with the result # from getWfTransitions dl.add(transition.id, transition.actbox_name) return dl.sortedByValue()