def sortedEventsBySlots(self,events): """Sorted events by slot""" mp = getToolByName(self,'portal_properties') special_event_types_pro = mp.monet_calendar_event_properties.special_event_types special_event_types = DisplayList() for etype in special_event_types_pro: special_event_types.add(etype,_(etype)) sorted_events = {'morning':[], 'afternoon':[], 'night':[], 'allday':[], 'sequence_slots':['morning','afternoon','night','allday']} sorted_events_keys = sorted_events.keys() for event in events: inter = list(set(event.getEventType).intersection(set(special_event_types))) if inter: if not inter[0] in sorted_events['sequence_slots']: sorted_events['sequence_slots'].append(inter[0]) sorted_events[inter[0]] = [] sorted_events[inter[0]].append(event) continue for key in sorted_events_keys: if event.getSlots == key: sorted_events[key].append(event) return sorted_events
def getEventTypeVocab(self): mp = getToolByName(self,'portal_properties') items = mp.monet_calendar_event_properties.event_types vocab = DisplayList() for item in items: vocab.add(item,_(item)) return vocab
def testGetAsDisplayListWithCustomColumns(self): lst = DisplayList() lst.add('c', 'a') lst.add('f', 'd') self.assertEqual( self.field.getAsDisplayList(self.demo, 'The third', 'column1'), lst)
def testGetAsDisplayListWithCustomColumns(self): lst = DisplayList() lst.add('c', 'a') lst.add('f', 'd') self.assertEqual( self.field.getAsDisplayList(self.demo, 'The third', 'column1'), lst)
def getEventTypeVocab(self): mp = getToolByName(self, 'portal_properties') items = mp.monet_calendar_event_properties.event_types vocab = DisplayList() for item in items: vocab.add(item, _(item)) return vocab
def sortedEventsBySlots(self, events): """Sorted events by slot""" mp = getToolByName(self, 'portal_properties') special_event_types_pro = mp.monet_calendar_event_properties.special_event_types special_event_types = DisplayList() for etype in special_event_types_pro: special_event_types.add(etype, _(etype)) sorted_events = { 'morning': [], 'afternoon': [], 'night': [], 'allday': [], 'sequence_slots': ['morning', 'afternoon', 'night', 'allday'] } sorted_events_keys = sorted_events.keys() for event in events: inter = list( set(event.getEventType).intersection(set(special_event_types))) if inter: if not inter[0] in sorted_events['sequence_slots']: sorted_events['sequence_slots'].append(inter[0]) sorted_events[inter[0]] = [] sorted_events[inter[0]].append(event) continue for key in sorted_events_keys: if event.getSlots == key: sorted_events[key].append(event) return sorted_events
def getTagsAndTagsCount(results): from Products.Archetypes.atapi import Vocabulary, DisplayList from Products.Archetypes.utils import unique coll = {} for o in results: lstSubject = [] try: lstSubject = o.Subject except AttributeError: from p4a.plonecalendar.eventprovider import BrainEvent if isinstance(o,BrainEvent): lstSubject = o.context.Subject else: lstSubject = [] for eSub in lstSubject: if coll.get(eSub,None) is None: coll[eSub] = {'name':eSub,'count':1} else: coll[eSub]['count'] = coll.get(eSub)['count'] + 1 dl = DisplayList() collkeys = coll.keys() collkeys.sort(lambda x,y: cmp(x.lower(),y.lower()),reverse=False) for obj in collkeys: dl.add(coll[obj]['name'],coll[obj]['count']) return Vocabulary(dl,None,None)
def getEventTypeName(self, key): mp = getToolByName(self, 'portal_properties') event_types_pro = mp.monet_calendar_event_properties.event_types event_types = DisplayList() for etype in event_types_pro: event_types.add(etype, _(etype)) return event_types.getValue(key)
def makeVocab(self,list): """Takes in a list (of keywords) and returns a Vocabulary without a translation domain. """ dl = DisplayList() for i in list: dl.add(i,i) return Vocabulary(dl,None,None)
def getEventTypeName(self,key): mp = getToolByName(self,'portal_properties') event_types_pro = mp.monet_calendar_event_properties.event_types event_types = DisplayList() for etype in event_types_pro: event_types.add(etype,_(etype)) return event_types.getValue(key)
def getSlotsVocab(self): vocab = DisplayList() vocab.add('', _(u'-- Unspecified --')) vocab.add('morning', _(u'Morning')) vocab.add('afternoon', _(u'Afternoon')) vocab.add('night', _(u'Evening')) vocab.add('allday', _(u'All day long')) return vocab
def getSlotsVocab(self): vocab = DisplayList() vocab.add('', _(u'-- Unspecified --')) vocab.add('morning', _(u'Morning')) vocab.add('afternoon', _(u'Afternoon')) vocab.add('night', _(u'Evening')) vocab.add('allday', _(u'All day long')) return vocab
def makeVocab(self,list): """Takes in a list (of keywords) and returns a display list that is expected by the Vocabulary machinery. """ dl = DisplayList() for i in list: dl.add(i,i) return Vocabulary(dl, None, None)
def makeVocab(self, list): """Takes in a list (of keywords) and returns a Vocabulary without a translation domain. """ dl = DisplayList() for i in list: dl.add(i, i) return Vocabulary(dl, None, None)
def getSlotsName(self,key): mp = getToolByName(self,'portal_properties') special_event_types_pro = mp.monet_calendar_event_properties.special_event_types special_event_types = DisplayList() for etype in special_event_types_pro: special_event_types.add(etype,_(etype)) return (key in special_event_types) and special_event_types.getValue(key) or SlotsVocab[key]
def getAvailableIssueTransitions(self): """ Get the available transitions for the issue. """ wftool = getToolByName(self, "portal_workflow") transitions = DisplayList() transitions.add("", "No change") for tdef in wftool.getTransitionsFor(self): transitions.add(tdef["id"], tdef["title_or_id"]) return transitions
def getAvailableIssueTransitions(self): """ Get the available transitions for the issue. """ wftool = getToolByName(self, 'portal_workflow') transitions = DisplayList() transitions.add('', 'No change') for tdef in wftool.getTransitionsFor(self): transitions.add(tdef['id'], tdef['title_or_id']) return transitions
def getSlotsName(self, key): mp = getToolByName(self, 'portal_properties') special_event_types_pro = mp.monet_calendar_event_properties.special_event_types special_event_types = DisplayList() for etype in special_event_types_pro: special_event_types.add(etype, _(etype)) return (key in special_event_types ) and special_event_types.getValue(key) or SlotsVocab[key]
def getTagsVocab(self): """ Get the available areas as a DispayList. """ tracker = self.getTracker() tags = tracker.getTagsInUse() vocab = DisplayList() for t in tags: vocab.add(t, t) return vocab
def getAvailableIssueTransitions(self): """ Get the available transitions for the issue. """ wftool = getToolByName(self, 'portal_workflow') transitions = DisplayList() transitions.add('', 'No change') for tdef in wftool.getTransitionsFor(self): transitions.add(tdef['id'], tdef['title_or_id']) return transitions
def getTagsVocab(self): """ Get the available areas as a DispayList. """ tracker = self.getTracker() tags = tracker.getTagsInUse() vocab = DisplayList() for t in tags: vocab.add(t, t) return vocab
def getMembersVocab(self): """Get the members available as a DisplayList.""" m_tool = getToolByName(self, 'portal_membership') users = m_tool.searchForMembers() vocab = DisplayList() vocab.add('', 'N/A') for user in users: user_id = user.getId() user_name = user.getProperty('fullname') vocab.add(user_id, user_name) return vocab
def getReleasesVocab(self): """ Get the vocabulary of available releases, including the item (UNASSIGNED) to denote that a release is not yet assigned. """ vocab = DisplayList() vocab.add('(UNASSIGNED)', _(u'None')) tracker = self.getTracker() trackerVocab = tracker.getReleasesVocab() for k in trackerVocab.keys(): vocab.add(k, trackerVocab.getValue(k), trackerVocab.getValue(k)) return vocab
def getReleasesVocab(self): """ Get the vocabulary of available releases, including the item (UNASSIGNED) to denote that a release is not yet assigned. """ vocab = DisplayList() vocab.add("(UNASSIGNED)", _(u"None")) tracker = self.getTracker() trackerVocab = tracker.getReleasesVocab() for k in trackerVocab.keys(): vocab.add(k, trackerVocab.getValue(k), trackerVocab.getValue(k)) return vocab
def getPaperMembersVocab(self): """Return the members of the paper manager group, as a display list""" group_tool = getToolByName(self, 'portal_groups') if not self.getPaperManagerGroup(): return self.getMembersVocab() portal_group = group_tool.getGroupById(self.getPaperManagerGroup()) group_members = portal_group.getGroupMembers() vocab = DisplayList() for member in group_members: if member.getProperty('fullname'): vocab.add(member.getProperty('id'),member.getProperty('fullname')) else: vocab.add(member.getProperty('id'),member.getProperty('id')) return vocab
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()
def getAsDisplayList(self, instance, keyCol=None, valueCol=None): """Get two columns of each row as a DisplayList - the key columns is keyCol, and the value column is valueCol. If these are not given, use the first two columns, respectively. """ data = self.get(instance) if keyCol is None: keyCol = self.getColumnIds()[0] if valueCol is None: valueCol = self.getColumnIds()[1] lst = DisplayList() for r in data: lst.add(r[keyCol], r[valueCol]) return lst
def listReflectoCacheRules(self): if not HAS_CACHESETUP: return [] pcs=getToolByName(self, CACHE_TOOL_ID, None) if pcs is None: return [] rules=[(rule.getId(), rule.Title()) for rule in pcs.getRules().objectValues("ContentCacheRule") if "ReflectoFile" in rule.getContentTypes()] rules.sort(key=lambda x: x[1]) vocab=DisplayList() vocab.add("", "Default browser caching") vocab+=DisplayList(rules) return vocab
def getWfStatesDisplayList(self, wfName=config.ECA_WORKFLOW_ID): """ @return a DisplayList containing all state keys and state titles in assignment's workflow """ #LOG.info('xxx: getWfStatesDisplayList') dl = DisplayList(()) wtool = self.portal_workflow wf = wtool.getWorkflowById(wfName) stateKeys = self.getWfStates(wfName) for key in stateKeys: dl.add(key, wf.states[key].title) #return dl.sortedByValue() return dl
def getWfStatesDisplayList(self, wfName=config.ECA_WORKFLOW_ID): """ @return a DisplayList containing all state keys and state titles in assignment's workflow """ #LOG.info('xxx: getWfStatesDisplayList') dl = DisplayList(()) wtool = self.portal_workflow wf = wtool.getWorkflowById(wfName) stateKeys = self.getWfStates(wfName) for key in stateKeys: dl.add(key, wf.states[key].title) #return dl.sortedByValue() return dl
def related_features_vocab(self): """Get list of PLIPs possible to add to this release.""" catalog = getToolByName(self, 'portal_catalog') projectPath = self.context.getPhysicalPath()[:-2] if len(projectPath) > 1 and projectPath[-1] == 'portal_factory': projectPath = projectPath[:-2] search = catalog.searchResults(portal_type='PSCImprovementProposal', path='/'.join(projectPath)) items = [s for s in search] items.sort(lambda x, y: cmp(int(x.getId), int(y.getId))) lst = DisplayList() for i in items: title = i.Title if len(title) > 40: title = title[:40] + '...' lst.add(i.UID, title) return lst
def getRecurrenceDisplayList(self): """ Returns a display list of recurrence types. """ dl = DisplayList(()) dl.add(NO_RECURRENCE, _(u'once', default=u'once')) dl.add(DAILY, _(u'daily', default=u'daily')) dl.add(WEEKLY, _(u'weekly', default=u'weekly')) dl.add(MONTHLY, _(u'monthly',default=u'monthly')) #dl.add(YEARLY, _(u'yearly', default=u'yearly')) return dl
def related_features_vocab(self): """Get list of PLIPs possible to add to this release.""" catalog = getToolByName(self, 'portal_catalog') projectPath = self.context.getPhysicalPath()[:-2] if len(projectPath) > 1 and projectPath[-1] == 'portal_factory': projectPath = projectPath[:-2] search = catalog.searchResults(portal_type = 'PSCImprovementProposal', path = '/'.join(projectPath)) items = [s for s in search] items.sort(lambda x, y: cmp(int(x.getId), int(y.getId))) lst = DisplayList() for i in items: title = i.Title if len(title) > 40: title = title[:40] + '...' lst.add(i.UID, title) return lst
def getAvailableBackendsDL(self): """ Returns a display list of all (actually) available backends. """ #LOG.debug("xdebug: getAvailableBackendsDL") dl = DisplayList(()) # get all available backends from spooler setup utily backends = self._getAvailableBackends() #LOG.debug('xdebug: backends: ' + repr(backends)) for key in backends.keys(): id = key label = '%s (%s)' % (backends[key].get('name', '?'), backends[key].get('version', '?')) dl.add(id, label) return dl
def getGroupsDisplayList(self): """ Return all available groups as a display list. """ dl = DisplayList(()) dl.add(NO_GROUP, '----') # portal_groups.listGroups is deprecated and will be removed in # Plone 3.5. Use PAS searchGroups instead. #pas = getToolByName(self, 'acl_users') #groups = pas.searchGroups() groups_tool = getToolByName(self, 'portal_groups') groups = groups_tool.listGroups() #LOG.debug('getGroupsDisplayList: groups: %s' % groups) for group in groups: dl.add(group.getGroupId(), group.getGroupName()) return dl
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 getManagersVocab(self, strict=False): """ Get the managers available as a DisplayList. The first item is 'None', with a key of '(UNASSIGNED)'. Note, we now also allow Technicians here, unless we are called with 'strict' is True. """ tracker = self.getTracker() vocab = DisplayList() vocab.add('(UNASSIGNED)', _(u'None')) mtool = getToolByName(self, 'portal_membership') for item in tracker.getManagers(): user = mtool.getMemberById(item) if user: fullname = user.getProperty('fullname', item) or item else: fullname = item vocab.add(item, fullname) if not strict: for item in tracker.getTechnicians(): user = mtool.getMemberById(item) if user: fullname = user.getProperty('fullname', item) or item else: fullname = item vocab.add(item, fullname) return vocab
def getManagersVocab(self, strict=False): """ Get the managers available as a DisplayList. The first item is 'None', with a key of '(UNASSIGNED)'. Note, we now also allow Technicians here, unless we are called with 'strict' is True. """ vocab = DisplayList() vocab.add( '(UNASSIGNED)', _( u"not_assigned", default=u'(Not assigned)')) mtool = getToolByName(self, 'portal_membership') for item in self.getManagers(): user = mtool.getMemberById(item) if user: fullname = user.getProperty('fullname', item) or item else: fullname = item vocab.add(item, fullname) if not strict: for item in self.getTechnicians(): user = mtool.getMemberById(item) if user: fullname = user.getProperty('fullname', item) or item else: fullname = item vocab.add(item, fullname) return vocab
def getManagersVocab(self, strict=False): """ Get the managers available as a DisplayList. The first item is 'None', with a key of '(UNASSIGNED)'. Note, we now also allow Technicians here, unless we are called with 'strict' is True. """ tracker = self.getTracker() vocab = DisplayList() #vocab.add('(UNASSIGNED)', _(u'None')) for item in tracker.getManagers(): vocab.add(item, item) if not strict: for item in tracker.getTechnicians(): vocab.add(item, item) L = [] for iten in vocab: L.append({'id':iten,'label':vocab.getValue(iten)}) return L
def getSelectedBackendsDL(self, withNone=True): """Returns a display list of all backends selected for this site. """ #LOG.debug("Getting all selected backends as Archetypes.utils.DisplayList...") dl = DisplayList(()) if withNone: # set a value for no testing value = BACKEND_NONE dl.add(value, '----') for backend in self.getSelectedBackends(): if backend != None: isCached = self.backendValueCache.has_key(backend) #LOG.debug("Backend '%s' is cached: %s" % (backend, isCached)) if not isCached: isCached = self._cacheBackend(backend) #LOG.debug("xdebug: backend '%s' is cached: %s" % (backend, isCached)) # end if if isCached: #LOG.debug("xdebug: Adding backend '%s' to display list" % backend) dl.add(backend, '%s (%s)' % (self.backendValueCache[backend].get('name', '?'), self.backendValueCache[backend].get('version', '?')) ) else: LOG.warn("Cannot add backend '%s' to display list " "because it is not cached" % backend) # end if # end if # end for return dl
def _getTestsDisplayList(self, backend=None): """ Returns a display list of all available tests for a backend. """ result = DisplayList(()) if (backend == None): backend = self.backend ecaab_utils = getToolByName(self, config.ECS_NAME) tests = ecaab_utils.getBackendTestFields(backend) [result.add(key, tests[key]) for key in tests] return result
def getPortalGroupsVocab(self): """Return the portal groups, as a display list""" group_tool = getToolByName(self, 'portal_groups') portal_groups = group_tool.listGroups() vocab = DisplayList() vocab.add('', 'Use all portal Members') for group in portal_groups: if group.getProperty('title'): vocab.add(group.getProperty('id'),group.getProperty('title')) else: vocab.add(group.getProperty('id'),group.getProperty('id')) return vocab
def getManagersVocab(self): """ Get the managers available as a DisplayList. The first item is 'None', with a key of '(UNASSIGNED)'. """ tracker = self.getTracker() items = tracker.getManagers() vocab = DisplayList() vocab.add('(UNASSIGNED)', _(u'None'), 'poi_vocab_none') vocab.add('(AREAMANAGER)', _(u'Area Manager'), 'poi_vocab_area_manager') for item in items: vocab.add(item, item) return vocab
def getManagersVocab(self): """ Get the managers available as a DisplayList. The first item is 'None', with a key of '(UNASSIGNED)'. """ tracker = self.getTracker() items = tracker.getManagers() vocab = DisplayList() vocab.add("(UNASSIGNED)", _(u"None"), "poi_vocab_none") vocab.add("(AREAMANAGER)", _(u"Area Manager"), "poi_vocab_area_manager") for item in items: vocab.add(item, item) return vocab
def getManagersVocab(self, strict=False): """ Get the managers available as a DisplayList. The first item is 'None', with a key of '(UNASSIGNED)'. Note, we now also allow Technicians here, unless we are called with 'strict' is True. """ tracker = self.getTracker() vocab = DisplayList() vocab.add("(UNASSIGNED)", _(u"None")) for item in tracker.getManagers(): vocab.add(item, item) if not strict: for item in tracker.getTechnicians(): vocab.add(item, item) return vocab
def testGetAsDisplayList(self): lst = DisplayList() lst.add('a', 'b') lst.add('d', 'e') self.assertEqual(self.field.getAsDisplayList(self.demo), lst)