def getFields(self): fields = [] for schema_name, schema in self._getSchemas(): for field_name, field in getFieldsInOrder(schema): if IChoice.providedBy(field): fields.append(StringField( schema_name + '.' + field.__name__, required=field.required, schemata='categorization', widget=atapi.SelectionWidget( label = field.title, description = field.description, ), vocabulary = atapi.DisplayList([(t.value, t.title or t.token) for t in field.vocabulary]), )) elif ISet.providedBy(field) and IChoice.providedBy(field.value_type): # XXX should be set fields.append(LinesField( schema_name + '.' + field.__name__, required=field.required, schemata='categorization', widget=atapi.MultiSelectionWidget( label = field.title, description = field.description, ), vocabulary = atapi.DisplayList([(t.value, t.title or t.token) for t in field.value_type.vocabulary]), )) return fields
def getConstituencyVocab(self, master): """Vocab method that returns a vocabulary consisting of the constituencies from the given county. """ results = CONSTITUENCIES_LIST[master] results = [(item, item) for item in results] return atapi.DisplayList(results)
def _get_selection_vocab2(self): return atapi.DisplayList(( ('foo2', u'Foo 2'), ('complex2', u'C\xf6mpl\xe8x 2'), ('bar2', _domain1(u'Bar 2')), ('hello2', _domain2(u'Hello 2')), ))
def listTransitions(self): types = getToolByName(self, 'portal_types') createdType = self.getCreatedType() if createdType in types.keys(): workflows = getToolByName(self, 'portal_workflow') candidates = [] transitions = [] for workflow in [ workflows.get(key) for key in workflows.getChainForPortalType(createdType) if key in workflows.keys() ]: candidates.extend( workflow.states.get(workflow.initial_state).transitions) for transition in set(candidates): transitions.append((transition, workflows.getTitleForTransitionOnType( transition, createdType))) else: vocabulary = getUtility( IVocabularyFactory, name=u'plone.app.vocabularies.WorkflowTransitions')(self) transitions = [(term.value, term.title) for term in vocabulary] return atapi.DisplayList( [(u'', _(u'No transition'))] + sorted(transitions, lambda x, y: cmp(x[1].lower(), y[1].lower())))
def listRelatorTypes(self): context = aq_inner(self) config = context.aq_getConfig() configtype = config.getItemType_byPortalType(self.portal_type) return atapi.DisplayList([(relator.id(), relator.name()) for relator in configtype.relators()])
def getSampleVocabulary(self): """Get a sample vocabulary """ return atapi.DisplayList( (("sample", _(u"Sample value 1"),), ("sample2", _(u"Sample value 2"),),))
def get_plone_members(self): """ return filtered list of plone members as DisplayList """ global fmp_tool if fmp_tool and queryUtility(IFastmemberpropertiesTool, 'fastmemberproperties_tool'): log.debug("Use fastmemberpropertiestool to get memberproperties!") fmp_tool = queryUtility(IFastmemberpropertiesTool, 'fastmemberproperties_tool') member_properties = fmp_tool.get_all_memberproperties() else: log.info("We use plone API to get memberproperties, this is very \ slow on many members, please install inqbus.plone.fastmemberproperties to make it fast!" ) acl_userfolder = getToolByName(self, 'acl_users') member_objs = acl_userfolder.getUsers() member_properties = {} for member in member_objs: probdict = {} probdict['id'] = member.getUserId() probdict['email'] = member.getProperty('email') probdict['fullname'] = safe_unicode( member.getProperty('fullname')) member_properties[probdict['id']] = probdict if not member_properties: return [] try: results = atapi.DisplayList([ (id, property['fullname'] + ' - ' + property['email']) for id, property in member_properties.items() if config.EMAIL_RE.findall(property['email']) ]) except TypeError, e: log.error(":get_plone_members: error in member_properties %s/ \ properties:'%s'" % (e, member_properties.items()))
def get_subscriber_sources(self): result = atapi.DisplayList() result.add(u'default', _( u'EasyNewsletter_label_noSource', u'no external subscriber source')) for utility in getUtilitiesFor(ISubscriberSource): result.add(utility[0], utility[0]) return result
def get_delivery_services(self): result = atapi.DisplayList() result.add(u'mailhost', _( u'EasyNewsletter_label_PloneMailHost', u'Default Plone Mailhost')) for utility in getUtilitiesFor(IMailHost): if utility[0]: result.add(utility[0], utility[0]) return result
def getProvidersReferences(self): """ Return a sorted list of references """ field = self.getWrappedField('provider') providers = list(field._Vocabulary(self).items()) providers.sort(lambda a, b: cmp(a[1].lower(), b[1].lower())) return atapi.DisplayList(providers)
def Vocabulary(self, content_instance): portal_properties = getToolByName(content_instance, 'portal_properties') props = portal_properties.pigeonhole return atapi.DisplayList([ (x, x) for x in props.getProperty('ph_field_values_%s' % self.field_num) ])
def informationUnits(self, instance=None): """ Controlled vocabulary (DisplayList) of information units supported """ units = unit_map.keys() units.sort() return atapi.DisplayList(zip(units, units))
def getCompanySizes(self): """ Get the available company sizes Hardcoded for now, but may change later on """ return atapi.DisplayList([("none", _(u"none")), ("small", _(u"small")), ("medium", _(u"medium")), ("large", _(u"large"))])
def listAvailablePanels(self): context = aq_inner(self) panels = context.aq_getAvailablePanels() list = atapi.DisplayList() list.add('0',"None, let Organizers decide") for panel in panels: list.add(panel['uid'], "%s, proposed by %s" % (panel['description'],panel['creator'])) return list
def getDraftTypesVocabulary(self): """ Get the vocabulary of available draft types """ vocab = atapi.DisplayList() vocab.add('draft', 'Draft', 'draft') vocab.add('copyedited', 'Copy Edited Version', 'copyedited') vocab.add('published', 'Published Version', 'published') return vocab
def listPersons(context): ct = getToolByName(context, 'portal_catalog') brains = ct.searchResults(portal_type='Person') results = [( item.UID, item.Title, ) for item in brains] results.insert(0, ('', '--None--')) return atapi.DisplayList(results)
def getCSSClassesVocabulary(self): utility = queryUtility(ITinyMCE) if utility: translation_service = getToolByName(self, 'translation_service') return atapi.DisplayList([[style.split('|')[1], translation_service.utranslate(msgid=style.split('|')[0], domain="plone.tinymce", context=self)] \ for style in utility.tablestyles.splitlines()]) return tuple()
def getCommentTypesVocabulary(self): """ Get the vocabulary of available draft types """ vocab = atapi.DisplayList() vocab.add('internal', 'Internal EB Comment', 'internal') vocab.add('referee', 'Referee Report', 'referee') vocab.add('report', 'Report for the Author', 'report') # TODO: permission.. assigned. return vocab
def get_aggregation_templates(self): """ Return registered aggregation templates as DisplayList """ result = atapi.DisplayList() registry = getUtility(IRegistry) aggregation_templates = registry.get( 'Products.EasyNewsletter.content_aggregation_templates') for key, value in aggregation_templates.items(): result.add(key, value) result.add(u'custom', _(u'enl_label_custom_template', u'Custom template field')) return result
def getSkillLevels(self): return atapi.DisplayList(( ( "bad", _(u"Bad"), ), ( "good", _(u"Good"), ), ))
def getColumnsVocab(self): """Return list of columns""" cache, key, data = self.getCacheKey('column-vocab') if not data: columns_list = self.getColumns() columns = [('', 'None'),] if columns_list: for col in columns_list: columns.append((col.id, col.displayName)) data = atapi.DisplayList(columns) cache[key] = data return data
def getInsurancesNames(self): """ Consulta vocabulĂĄrio de convĂȘnios e retorna a lista. """ dl = atapi.DisplayList() dl.add('', '') portal = getSite() vt = getToolByName(portal, 'vocabulary_tool') vocab_list = vt.get_vocabulary('insurance', 2) for vocab in vocab_list: dl.add(vocab, vocab) dl.add('outro_plano', 'Outro') return dl
def getDrives(self): """return List of Drives""" cache, key, data = self.getCacheKey('drive-list') if not data: sharepoint = self.getSharepoint() list_o_drives = [('', 'None'),] if sharepoint: site = self.getSharepointSite() if site: for d in site.getDrives(): list_o_drives.append((d.id, d.name + ' ' + d.webUrl )) data = atapi.DisplayList(list_o_drives) cache[key] = data return data
def getLists(self): """return List of Lists""" cache, key, data = self.getCacheKey('list-list') if not data: sharepoint = self.getSharepoint() list_o_lists = [('', 'None'),] if sharepoint: site = self.getSharepointSite() if site: for l in site.getLists(): list_o_lists.append((l.id, l.displayName + ' ' + l.webUrl )) data = atapi.DisplayList(list_o_lists) cache[key] = data return data
def getSites(self): """return List of sites""" cache, key, data = self.getCacheKey('site-list') if not data: sitelist = [] sharepoint = self.getSharepoint() if sharepoint: for site in sharepoint.getSitesList(): sitelist.append((site.siteId, site.displayName + ' ' + site.webUrl)) sitelist.sort(key=lambda x: x[1]) data = atapi.DisplayList(sitelist) cache[key] = data return data
def get_output_templates(self): """ Return registered output templates as DisplayList """ result = atapi.DisplayList() registry = getUtility(IRegistry) output_templates = registry.get( 'Products.EasyNewsletter.output_templates') if not output_templates: return result for key, value in output_templates.items(): result.add(key, value) if not len(result): result.add(u'output_default', _( u'enl_label_default_output_template', u'Default output template')) return result
def getDisplayList(self, instance): """ returns a object of class DisplayList as defined in Products.Archetypes.utils. The instance of the content class is given as parameter. """ vocab = self.getVocabulary(instance) if isinstance(vocab, TreeVocabulary): dlist = vocab.getDisplayList(instance, display_parents=self.display_parents) else: dlist = vocab.getDisplayList(instance) if self.empty_first_item: item = self.custom_empty_first_item or [(u'', u'--'), ] dlist = atapi.DisplayList(item) + dlist return dlist
def getAvailableTransitions(self): # Create a temporary object so we can ask what transitions are # available for it. id = 'temp_zest_temp' self.invokeFactory('FeedFeederItem', id) wf_tool = getToolByName(self, 'portal_workflow') transitions = wf_tool.getTransitionsFor(self[id]) display_trans = [ ('', _('Keep initial state')), ] for trans in transitions: display_trans.append((trans['id'], trans['name'])) # Unindex and remove the temporary object self[id].unindexObject() self._delOb(id) return atapi.DisplayList(display_trans)
def vocabulary_issues(self): pairs = [] poiview = self.restrictedTraverse('@@xm-poi') for brain in poiview.get_open_issues_in_project(): issue = brain.getObject() label = '#%s: %s' % (issue.getId(), issue.Title()) pairs.append((issue.UID(), label)) # Guard against losing our issues when they are closed and we # still want to edit this PoiTask. See # http://plone.org/products/extreme-management-tool/issues/58/ keys = [key for key, value in pairs] for issue in self.getIssues(): if issue.UID() not in keys: label = '#%s: %s' % (issue.getId(), issue.Title()) pairs.append((issue.UID(), label)) pairs = sorted(pairs, lambda a, b: cmp(a[1], b[1])) return atapi.DisplayList(pairs)
def listContentFields(self): types = getToolByName(self, 'portal_types') createdType = self.getCreatedType() def smart_title(title, key): if not isinstance(title, Message): return u'{0:s} ({1:s})'.format(title, key) else: # Don't brake i18n messages return title if createdType in types.keys(): mapping = self._getDexterityFields(createdType) fields = [(key, smart_title(mapping[key].title, key)) for key in mapping] else: fields = [] return atapi.DisplayList(fields)