本文整理汇总了Python中zope.schema.vocabulary.SimpleVocabulary.search方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleVocabulary.search方法的具体用法?Python SimpleVocabulary.search怎么用?Python SimpleVocabulary.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.schema.vocabulary.SimpleVocabulary
的用法示例。
在下文中一共展示了SimpleVocabulary.search方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getVocabulary
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import search [as 别名]
def getVocabulary(self):
members = get_users(groupname=self.groupName)
pairs = [ dict(id=mm.id, fullname=mm.getProperty('fullname')) for mm in members ]
createTerm = SimpleVocabulary.createTerm
terms = [createTerm(mm['id'], mm['id'], (u"%s (%s)" % (mm['fullname'],mm['id'])).encode('utf-8'))
for mm in pairs ]
vocabulary = SimpleVocabulary(terms)
def search(self,query):
return [v for v in self if query.lower() in v.value.lower()]
vocabulary.search = partial(search,vocabulary)
return vocabulary
示例2: producent_source
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import search [as 别名]
def producent_source(context):
"""
Populate vocabulary with values from portal_catalog.
@param context: z3c.form.Form context object (in our case site root)
@return: SimpleVocabulary containing all areas as terms.
"""
# Acquire portal catalog
portal_catalog = api.portal.get_tool(name='portal_catalog')
brains = portal_catalog({'object_provides': IProducent.__identifier__})
# Create a list of tuples (UID, Title) of results
terms = [ SimpleTerm(value=brain['UID'], token=brain['UID'], title=brain['Title']) for brain in brains ]
vocab = SimpleVocabulary(terms)
vocab.search = search_producents
return vocab