当前位置: 首页>>代码示例>>Python>>正文


Python SimpleVocabulary.fromValues方法代码示例

本文整理汇总了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])
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:collective.alias,代码行数:14,代码来源:vocabulary.py

示例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
开发者ID:ulif,项目名称:psj.content,代码行数:14,代码来源:sources.py

示例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)
开发者ID:collective,项目名称:Products.Poi,代码行数:15,代码来源:tracker.py

示例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
开发者ID:niteoweb,项目名称:niteoweb.aweber,代码行数:15,代码来源:interfaces.py

示例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([])
开发者ID:collective,项目名称:Products.Poi,代码行数:15,代码来源:tracker.py

示例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)
开发者ID:4teamwork,项目名称:Products.TinyMCE,代码行数:9,代码来源:vocabularies.py

示例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'
     ])
开发者ID:sweemeng,项目名称:collective.conference,代码行数:9,代码来源:vocabulary.py

示例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
开发者ID:PublicaMundi,项目名称:ckanext-publicamundi,代码行数:27,代码来源:test_xml_serializers.py

示例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
开发者ID:Martronic-SA,项目名称:collective.behavior.sql,代码行数:18,代码来源:sql_views.py

示例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)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:9,代码来源:reports.py

示例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
开发者ID:antarctica,项目名称:ckanext-publicamundi,代码行数:35,代码来源:test_formatters.py

示例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])
开发者ID:immunarray,项目名称:immunarray.lims,代码行数:9,代码来源:material.py

示例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)
开发者ID:borinot,项目名称:plone.app.event,代码行数:37,代码来源:vocabularies.py

示例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)
开发者ID:kingel,项目名称:plone.app.event,代码行数:9,代码来源:vocabulary.py

示例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
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:36,代码来源:_field.py


注:本文中的zope.schema.vocabulary.SimpleVocabulary.fromValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。