本文整理汇总了Python中zope.schema.vocabulary.SimpleVocabulary.fromValues方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleVocabulary.fromValues方法的具体用法?Python SimpleVocabulary.fromValues怎么用?Python SimpleVocabulary.fromValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.schema.vocabulary.SimpleVocabulary
的用法示例。
在下文中一共展示了SimpleVocabulary.fromValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def __call__(self, context):
site = getSite()
if site is None:
return SimpleVocabulary.fromValues([])
ttool = getToolByName(site, 'portal_types', None)
if ttool is None:
return SimpleVocabulary.fromValues([])
items = [(ttool[t].Title(), t) for t in ttool.listContentTypes()]
items.sort()
return SimpleVocabulary([SimpleTerm(i[1], i[1], i[0]) for i in items])
示例2: __call__
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def __call__(self, context):
if self.vocab is not None:
return self.vocab
util = queryUtility(IExternalVocabConfig, name=self.name)
if util is None:
return SimpleVocabulary.fromValues([])
path = util.get('path', None)
if not path or not os.path.isfile(path):
return SimpleVocabulary.fromValues([])
self.vocab = SimpleVocabulary(
make_terms([line.strip() for line in open(path, 'r')]))
return self.vocab
示例3: possibleSeverities
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def possibleSeverities(context):
"""
Get the available severities as a Vocabulary.
"""
if ITracker.providedBy(context):
tracker = context
elif hasattr(context, 'getTracker'):
tracker = context.getTracker()
elif hasattr(context, 'context'):
tracker = context.context.getTracker()
else:
return SimpleVocabulary.fromValues(DEFAULT_SEVERITIES)
return SimpleVocabulary.fromValues(tracker.available_severities)
示例4: __call__
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def __call__(self, context):
"""Read from available_lists_record."""
result = None
try:
lists_record = api.portal.get_registry_record(
'niteoweb.aweber.available_lists_record')
if lists_record:
result = SimpleVocabulary.fromValues(lists_record)
else:
result = SimpleVocabulary.fromValues([])
except KeyError:
result = SimpleVocabulary.fromValues([])
return result
示例5: possibleTargetReleases
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def possibleTargetReleases(context):
"""
Get the available target release as a Vocabulary.
"""
if ITracker.providedBy(context):
tracker = context
elif hasattr(context, 'getTracker'):
tracker = context.getTracker()
else:
return SimpleVocabulary.fromValues([])
if tracker.available_releases:
return SimpleVocabulary.fromValues(tracker.available_releases)
return SimpleVocabulary([])
示例6: plugins_vocabulary
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def plugins_vocabulary(context):
""" A vocabulary containing all the allowed plugins for TinyMCE
"""
from Products.TinyMCE.interfaces.utility import DEFAULT_PLUGINS
plugins = DEFAULT_PLUGINS[:]
plugins.sort()
return SimpleVocabulary.fromValues(plugins)
示例7: __call__
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def __call__(self, context):
return SimpleVocabulary.fromValues([
u'Talk',
u'Hackfest',
u'Workshop',
u'Discussion'
])
示例8: test_field_dict_of_textline
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def test_field_dict_of_textline():
f = zope.schema.Dict(
title = u'Addresses',
description = u'A collection of addresses',
required = True,
value_type = zope.schema.TextLine(
title = u'Street Address'
),
key_type = zope.schema.Choice(
title = u'Address Type',
vocabulary = SimpleVocabulary.fromValues([
'work', 'home', 'laboratory',
])
),
)
#f.value_type.setTaggedValue('name', 'street_address')
v = {
'work': u'Acacia Avenue 22',
'home': u'Nowhere Land',
}
f.validate(v)
yield _test_field, '-', 'addresses', f, v
示例9: updateFields
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def updateFields(self):
fields = field.Fields(ITestForm)
connections = []
for name, url in self.saconnect.items():
connections.append(SimpleTerm(url, url, name))
fields['connection'].field.vocabulary = SimpleVocabulary(connections)
if len(connections) == 1:
if self.Base == None:
self.initBase(connections[0].value)
self.tablesVoc = self.getTables()
fields['table'].field.vocabulary = SimpleVocabulary.fromValues(self.tablesVoc)
if len(self.tablesVoc) == 1:
self.columnsVoc = self.getColumns(self.tablesVoc[0])
fields['columns'].field.value_type.vocabulary = SimpleVocabulary.fromValues(self.columnsVoc)
fields['columns'].field.default = fields['columns'].field.values
self.fields = fields
示例10: tabledDocumentOptions
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def tabledDocumentOptions(context):
items = (_(u"Title"),
_(u"Number"),
_(u"Text"),
_(u"Owner"),
)
return SimpleVocabulary.fromValues(items)
示例11: test_field_dicts
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def test_field_dicts():
print
# [Dict, TextLine]
f = zope.schema.Dict(
title=u"A map of keywords",
key_type=zope.schema.Choice(vocabulary=SimpleVocabulary.fromValues(("alpha", "alpha-el", "nonsence"))),
value_type=zope.schema.TextLine(title=u"Keyword"),
)
v = {"alpha": u"alpha", "alpha-el": u"αλφα", "nonsence": u'ειμαι "βράχος"'}
f.validate(v)
for name in ["default"]:
formatter = formatter_for_field(f, name)
verifyObject(IFormatter, formatter)
s = formatter.format(v)
print " -- format:%s %s -- " % (name, type(f))
print s
# [Dict, *]
f = schemata.IFooMetadata.get("contacts")
v = {"personal": fixtures.contact1, "office": fixtures.contact2}
f.validate(v)
for name in ["default"]:
formatter = formatter_for_field(f, name)
verifyObject(IFormatter, formatter)
s = formatter.format(v)
print " -- format:%s %s -- " % (name, type(f))
print s
示例12: __call__
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def __call__(self, context):
brains = find(
object_provides='immunarray.lims.interfaces.material.IMaterial',
remaining_amount={'query': 1, 'range': 'min'},
sort_on='sortable_title',
**self.kwargs)
return SimpleVocabulary.fromValues([brain.Title for brain in brains])
示例13: EventTypes
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def EventTypes(context):
""" Vocabulary for available event types.
Insane stuff: All types are created temporary and checked if the provide
the IEvent interface. At least, this function is cached forever the Zope
process lives.
"""
# TODO: I'd love to query the factory for types, who's instances are
# implementing a specific interface via the portal_factory API.
portal = getSite()
tmp_folder_id = 'event_types_temp_folder__%s' % random.randint(0, 99999999)
portal.invokeFactory('Folder', tmp_folder_id)
try:
tmp_folder = portal._getOb(tmp_folder_id)
portal_types = getToolByName(portal, 'portal_types')
all_types = portal_types.listTypeInfo(portal)
event_types = []
cnt = 0
for fti in all_types:
if not getattr(fti, 'global_allow', False):
continue
cnt += 1
tmp_id = 'temporary__event_types__%s' % cnt
tmp_obj = None
fti.constructInstance(tmp_folder, tmp_id)
tmp_obj = tmp_folder._getOb(tmp_id)
if tmp_obj:
if IEvent.providedBy(tmp_obj):
event_types.append(fti.id)
finally:
# Delete the tmp_folder again
tmp_folder.__parent__.manage_delObjects([tmp_folder_id])
return SimpleVocabulary.fromValues(event_types)
示例14: Timezones
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def Timezones(context):
""" Vocabulary for all timezones.
TODO: make timezone source adaptable to provide vocab with commont_timezones
or all_timezones
"""
return SimpleVocabulary.fromValues(pytz.all_timezones)
示例15: __init__
# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromValues [as 别名]
def __init__(self, values=None, vocabulary=None, source=None, **kw):
"""Initialize object."""
if vocabulary is not None:
assert (isinstance(vocabulary, basestring)
or IBaseVocabulary.providedBy(vocabulary))
assert source is None, (
"You cannot specify both source and vocabulary.")
elif source is not None:
vocabulary = source
assert not (values is None and vocabulary is None), (
"You must specify either values or vocabulary.")
assert values is None or vocabulary is None, (
"You cannot specify both values and vocabulary.")
self.vocabulary = None
self.vocabularyName = None
if values is not None:
self.vocabulary = SimpleVocabulary.fromValues(values)
elif isinstance(vocabulary, (unicode, str)):
self.vocabularyName = vocabulary
else:
assert (ISource.providedBy(vocabulary) or
IContextSourceBinder.providedBy(vocabulary))
self.vocabulary = vocabulary
# Before a default value is checked, it is validated. However, a
# named vocabulary is usually not complete when these fields are
# initialized. Therefore signal the validation method to ignore
# default value checks during initialization of a Choice tied to a
# registered vocabulary.
self._init_field = (bool(self.vocabularyName) or
IContextSourceBinder.providedBy(self.vocabulary))
super(Choice, self).__init__(**kw)
self._init_field = False