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


Python SimpleVocabulary.fromItems方法代码示例

本文整理汇总了Python中zope.schema.vocabulary.SimpleVocabulary.fromItems方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleVocabulary.fromItems方法的具体用法?Python SimpleVocabulary.fromItems怎么用?Python SimpleVocabulary.fromItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zope.schema.vocabulary.SimpleVocabulary的用法示例。


在下文中一共展示了SimpleVocabulary.fromItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tagging_vocabulary_factory

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def tagging_vocabulary_factory(context):
    items = []
    items.append(('ttn', u'TagThe.Net'))
    items.append(('tpcom', u'text-processing.com'))
    try:
        registry = getUtility(IRegistry)
        settings = registry.forInterface(ITagHelperSettingsSchema)
        if settings.silcc_url:
            items.append(('silcc', u'SiLLC'))
        if settings.yahoo_api_key:
            items.append(('yahoo', u'Yahoo'))
        if settings.alchemy_api_key:
            items.append(('alchemy', u'AlchemyAPI'))
        if settings.calais_api_key:
            items.append(('calais', u'Open Calais'))
        if settings.zemanta_api_key:
            items.append(('zemanta', u'Zemanta'))
        if settings.openamplify_api_key:
            items.append(('openamplify', u'OpenAmplify'))
        if settings.evri_api_key:
            items.append(('evri', u'Evri'))

    except (KeyError, AttributeError):
        return SimpleVocabulary.fromItems(items)
    return SimpleVocabulary.fromItems(items)
开发者ID:collective,项目名称:collective.taghelper,代码行数:27,代码来源:vocabularies.py

示例2: getProfiles

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def getProfiles(context):
    """
    Return list of Google Analytics profiles and corresponding
    account IDs (e.g. ga:30481).
    """
    
    analytics_tool = getToolByName(getSite(), 'portal_analytics')
    
    try:
        accounts = analytics_tool.getAccountsFeed()
    except error.BadAuthenticationError:
        choices = [('Please authorize with Google in the Google Analytics \
            control panel.', None)]
        return SimpleVocabulary.fromItems(choices)
    except error.RequestTimedOutError:
        choices = [('The request to Google Analytics timed out. Please try \
            again later.', None)]
        return SimpleVocabulary.fromItems(choices)
    if accounts:
        unique_choices = {}
        for entry in accounts.entry:
            unique_choices.update({entry.title.text : entry.tableId[0].text})
        choices = unique_choices.items()
    else:
        choices = [('No profiles available', None)]
    return SimpleVocabulary.fromItems(choices)
开发者ID:ajussis,项目名称:cip.knowledgeportals,代码行数:28,代码来源:vocabularies.py

示例3: getWebProperties

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def getWebProperties(context):
    """
    Return list of Google Analytics profiles and web property
    IDs (e.g. UA-30481-22).
    """

    analytics_tool = getToolByName(getSite(), "portal_analytics")
    # short circuit if user hasn't authorized yet
    if not analytics_tool.auth_token:
        return SimpleVocabulary([])

    try:
        accounts = analytics_tool.getAccountsFeed("accounts/~all/webproperties/~all/profiles")
    except error.BadAuthenticationError:
        choices = [
            (
                "Please authorize with Google in the Google Analytics \
            control panel.",
                None,
            )
        ]
        return SimpleVocabulary.fromItems(choices)
    except error.RequestTimedOutError:
        choices = [
            (
                "The request to Google Analytics timed out. Please try \
            again later.",
                None,
            )
        ]
        return SimpleVocabulary.fromItems(choices)
    if accounts:
        unique_choices = {}
        # In vocabularies, both the terms and the values must be unique. Since
        # there can be more than one profile for a given web property, we create a list
        # of all the profiles for each property. (Ideally we would use the URL for the
        # web property, but Google doesn't expose it through the Analytics API.)
        for entry in accounts.entry:
            for prop in entry.property:
                if prop.name == "ga:profileName":
                    title = prop.value
                    if not isinstance(title, unicode):
                        title = unicode(title, "utf-8")
                if prop.name == "ga:webPropertyId":
                    webPropertyId = prop.value
            if not webPropertyId in unique_choices.keys():
                unique_choices.update({webPropertyId: title})
            else:
                unique_choices[webPropertyId] += ", " + title
        # After we reverse the terms so that the profile name(s) is now the key, we need
        # to ensure that these keys are unique. So, we pass the resulting list through
        # dict() and then output a list of items.
        choices = dict([(title, property_id) for (property_id, title) in unique_choices.items()]).items()
    else:
        choices = [("No profiles available", None)]
    return SimpleVocabulary([SimpleTerm(c[1], c[1], c[0]) for c in choices])
开发者ID:fulv,项目名称:collective.googleanalytics,代码行数:58,代码来源:vocabularies.py

示例4: __call__

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
 def __call__(self, context):
     """Retrieve available themes inside persistent resource and add
     sunburst and collective.js.jqueryui themes"""
     tm = self.getThemeManager()
     try:
         ids = tm.getThemeIds()
         ids.sort()
         items = [(id, id) for id in ids if id]
         return SimpleVocabulary.fromItems(items)
     except TypeError:
         logger.info('kss inline validation ... getSite doesn t return Plone site')
         return SimpleVocabulary.fromItems([('sunburst','sunburst')])
开发者ID:Martronic-SA,项目名称:collective.jqueryuithememanager,代码行数:14,代码来源:vocabulary.py

示例5: topic_vocab_factory

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def topic_vocab_factory(context):
    """get all potential topics for corpuses"""
    try:
        registry = getUtility(IRegistry)
        site = registry.getParentNode()
        catalog = getToolByName(site, 'portal_catalog')
        query = {'portal_type': 'Topic', 'sort_on': 'sortable_title'}
        brains = catalog(**query)
        ppl = len('/'.join(site.getPhysicalPath()))
        items=[(brain.Title[:15] +' - ' + brain.getPath()[ppl:], brain.UID)
            for brain in brains]
        return SimpleVocabulary.fromItems(items)
    except:
        return SimpleVocabulary.fromItems([('Title', 'UID'),])
开发者ID:collective,项目名称:collective.simserver.core,代码行数:16,代码来源:vocabulary.py

示例6: __call__

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
 def __call__(self, context):
     cats = context._database.getCats()
     items = [
         (i.title, i.gcid)
         for i in cats
     ]
     return SimpleVocabulary.fromItems(items)
开发者ID:smcmahon,项目名称:dcn.eventreader,代码行数:9,代码来源:orgedit.py

示例7: __call__

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
 def __call__(self, context):
     brains = find(IProvider.__identifer__)
     values = [b.getObject() for b in brains]
     names = [" ".join([str(v.site_ID), v.first_name, v.last_name])
              for v in values]
     items = [(n, normalize(n)) for n in names]
     return SimpleVocabulary.fromItems(items)
开发者ID:immunarray,项目名称:immunarray.lims,代码行数:9,代码来源:provider.py

示例8: __call__

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
    def __call__(self, context):
        countries = {}
        if ISectorContainer.providedBy(context):
            for country in context.values():
                if not ICountry.providedBy(country):
                    continue
                countries.update({
                    utils.getRegionTitle(context.REQUEST,
                                         country.id,
                                         country.title).encode('utf-8'):
                    country.id
                })
        elif ICountry.providedBy(context):
            countries.update({
                utils.getRegionTitle(
                    context.REQUEST,
                    context.id,
                    context.title).encode('utf-8'): context.id
            })
        elif ISector.providedBy(context) or ISurveyGroup.providedBy(context):
            if ISector.providedBy(context):
                country = aq_parent(context)
            elif ISurveyGroup.providedBy(context):
                country = aq_parent(aq_parent(context))

            if ICountry.providedBy(country):
                countries.update({
                    utils.getRegionTitle(
                        context.REQUEST,
                        country.id,
                        country.title).encode('utf-8'): country.id
                })
        return SimpleVocabulary.fromItems(sorted(countries.items()))
开发者ID:garbas,项目名称:osha.oira,代码行数:35,代码来源:vocabularies.py

示例9: managerdatasource_handler

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def managerdatasource_handler(_context, name, json_source, site=None, 
                            title=u'Officials by Group',
                            description=u'Looks up officials from a group list',
                            select_label=u'Group',
                            select_description=u'Please select a group',
                            form_label=u'Your letter will be sent to:'):

    adapter_factory = type(str(name), (ManagerLRS,), {
        'name': name,
        'form_label': form_label,
    })

    json_data = simplejson.loads(open(json_source).read())

    vocab = SimpleVocabulary.fromItems([
                (i,i) for i in sorted(json_data.keys())
            ])


    class ISetting(Interface):
        settingsdata = schema.Choice(
            title=select_label,
            description=select_description,
            vocabulary=vocab
        )

    _register_datasource(_context,
                        name, json_source, site,
                        title, description,
                        select_label, select_description,
                        ISetting,
                        adapter_factory)
开发者ID:inigoconsulting,项目名称:collective.megaphonegrouplookup,代码行数:34,代码来源:meta.py

示例10: ImportanceVocabulary

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def ImportanceVocabulary(context):
    items =[
        (_(u"importance_highest", default=u"Highest importance"),'4'),
        (_(u"importance_high", default=u"High importance"),'3'),
        (_(u"importance_normal", default=u"Normal importance"),'2'),
        (_(u"importance_low", default=u"Low importance"),'1')]
    return SimpleVocabulary.fromItems(items)
开发者ID:dougstefe,项目名称:collective.teaser,代码行数:9,代码来源:vocabularies.py

示例11: test_vocabulary

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
 def test_vocabulary(self):
     from zope.schema.vocabulary import SimpleVocabulary
     vocab = SimpleVocabulary.fromItems((
         (u"Foo", "id_foo"),
         (u"Bar", "id_bar")))
     res = getAdapter(vocab, interface=IValueToJson)
     self.assertEqual(type(res), list)
开发者ID:plone,项目名称:plone.server,代码行数:9,代码来源:test_adapters.py

示例12: __init__

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
    def __init__(self, table, token_field, value_field):
        self.table = table
        self.token_field = token_field
        self.value_field = value_field

        terms = select([getattr(table.c, value_field), getattr(table.c, token_field)]).execute().fetchall()
        self.vocabulary = SimpleVocabulary.fromItems(terms)
开发者ID:BGCX261,项目名称:zope-alchemist-svn-to-git,代码行数:9,代码来源:vocabulary.py

示例13: get_index_types

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def get_index_types(obj):
    """ Vocabulary for the 'Index type' dropdown.
    """
    types = get_field_types()
    if isinstance(obj, PlominoField):
        default_index = types[obj.field_type][1]
        indexes = [('Default (%s)' % default_index, 'DEFAULT'), ]
    else:
        indexes = [('Default', 'DEFAULT'), ]
    db = obj.getParentDatabase()
    idx = db.getIndex()
    index_ids = [i['name'] for i in idx.Indexes.filtered_meta_types()]
    for i in index_ids:
        if i in ['GopipIndex', 'UUIDIndex']:
            # Index types internal to Plone
            continue
        label = "%s%s" % (
            i, {
                "FieldIndex": " (match exact value)",
                "ZCTextIndex": " (match any contained words)",
                "KeywordIndex": " (match list elements)"
            }.get(i, '')
        )
        indexes.append((label, i))
    return SimpleVocabulary.fromItems(indexes)
开发者ID:pretaweb,项目名称:Plomino,代码行数:27,代码来源:field.py

示例14: ImageScaleVocabulary

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def ImageScaleVocabulary(context):
    allowed_sizes = getAllowedSizes()
    items = [
        (u'%s(%s, %s)' % (key, value[0], value[1]), key)
        for key, value in allowed_sizes.items() if allowed_sizes
    ]
    return SimpleVocabulary.fromItems(items)
开发者ID:collective,项目名称:collective.folderishtypes,代码行数:9,代码来源:vocabularies.py

示例15: get_columns

# 需要导入模块: from zope.schema.vocabulary import SimpleVocabulary [as 别名]
# 或者: from zope.schema.vocabulary.SimpleVocabulary import fromItems [as 别名]
def get_columns(obj):
    """ Get a list of current view's columns
    """
    if not hasattr(obj, 'getColumns'):
        return None
    columns = [(c.id, c.id) for c in obj.getColumns()]
    return SimpleVocabulary.fromItems(columns)
开发者ID:Gagaro,项目名称:Plomino,代码行数:9,代码来源:view.py


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