本文整理汇总了Python中zope.schema.vocabulary.SimpleVocabulary类的典型用法代码示例。如果您正苦于以下问题:Python SimpleVocabulary类的具体用法?Python SimpleVocabulary怎么用?Python SimpleVocabulary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleVocabulary类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: getTransitionVocab
def getTransitionVocab(context):
if AccessControl.getSecurityManager(
).getUser() == AccessControl.SpecialUsers.nobody:
return SimpleVocabulary([])
wftool = getToolByName(context, 'portal_workflow')
transitions = []
if opengever.task.task.ITask.providedBy(context) and \
context.REQUEST.URL.find('++add++opengever.task.task') == -1:
for tdef in wftool.getTransitionsFor(context):
transitions.append(SimpleVocabulary.createTerm(
tdef['id'],
tdef['id'],
PMF(tdef['id'], default=tdef['title_or_id'])))
return SimpleVocabulary(transitions)
else:
wf = wftool.get(wftool.getChainForPortalType('opengever.task.task')[0])
state = wf.states.get(wf.initial_state)
for tid in state.transitions:
tdef = wf.transitions.get(tid, None)
transitions.append(SimpleVocabulary.createTerm(
tdef.id,
tdef.id,
PMF(tdef.id, default=tdef.title_or_id)))
return SimpleVocabulary(transitions)
开发者ID:pemzurigo,项目名称:opengever.core,代码行数:27,代码来源:util.py
示例2: KeywordSource
class KeywordSource(object):
interface.implements(IQuerySource)
def __init__(self, context):
self.context = context
catalog = getToolByName(context, 'portal_catalog')
self.keywords = catalog.uniqueValuesFor('Subject')
terms = []
for x in self.keywords:
terms.append(SimpleTerm(x, x, unicode(x)))
self.vocab = SimpleVocabulary(terms)
def __contains__(self, term):
return self.vocab.__contains__(term)
def __iter__(self):
return self.vocab.__iter__()
def __len__(self):
return self.vocab.__len__()
def getTerm(self, value):
return self.vocab.getTerm(value)
def getTermByToken(self, value):
return self.vocab.getTermByToken(value)
def search(self, query_string):
q = query_string.lower()
return [self.getTerm(kw) for kw in self.keywords if q in kw.lower()]
开发者ID:collective,项目名称:collective.z3cform.html5widgets,代码行数:30,代码来源:html5widgets.py
示例3: KeywordSource
class KeywordSource(object):
implements(IQuerySource)
def __init__(self, context):
self.context = context
self.vocab = SimpleVocabulary(
[SimpleVocabulary.createTerm(DATA[x], x, DATA[x])
for x in DATA]
)
def __contains__(self, term):
return self.vocab.__contains__(term)
def __iter__(self):
return self.vocab.__iter__()
def __len__(self):
return self.vocab.__len__()
def getTerm(self, value):
return self.vocab.getTerm(value)
def getTermByToken(self, value):
return self.vocab.getTermByToken(value)
def search(self, query_string):
q = query_string.lower()
return [kw
for kw in self.vocab._terms
if q.lower() in kw.value]
开发者ID:cedricmessiant,项目名称:collective.z3cform.chosen,代码行数:30,代码来源:demo.py
示例4: list_templates
def list_templates(context):
"""Return a list available templates."""
templates = get_oneoffixx_templates()
template_group = context.REQUEST.form.get('form.widgets.template_group')
terms = []
for template in templates:
terms.append(SimpleVocabulary.createTerm(
template, template.template_id, template.title))
# We filter templates when template_group has been selected
if template_group is not None:
favorites = get_oneoffixx_favorites()
# Favorites are a special case
if favorites and template_group[0] == favorites.get('id'):
terms = [
SimpleVocabulary.createTerm(
OneOffixxTemplate(
template, favorites.get('localizedName', '')),
template.get('id'),
template.get('localizedName'),
)
for template in favorites.get('templates')
]
elif template_group[0] != '--NOVALUE--':
terms = [term for term in terms if term.value.group == template_group[0]]
return MutableObjectVocabulary(terms)
开发者ID:4teamwork,项目名称:opengever.core,代码行数:28,代码来源:form.py
示例5: tagging_vocabulary_factory
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,代码行数:25,代码来源:vocabularies.py
示例6: attachable_documents_vocabulary
def attachable_documents_vocabulary(context):
terms = []
user = AccessControl.getSecurityManager().getUser()
if user == AccessControl.SpecialUsers.nobody:
return SimpleVocabulary(terms)
intids = getUtility(IIntIds)
ids = []
for doc in context.getFolderContents(
full_objects=True,
contentFilter={'portal_type': ['opengever.document.document',
'ftw.mail.mail']}):
key = str(intids.getId(doc))
label = doc.Title()
terms.append(SimpleVocabulary.createTerm(key, key, label))
ids.append(key)
for relation in getattr(context, 'relatedItems', []):
key = str(relation.to_id)
# check if the task doesn't contain the related document allready
if key in ids:
continue
label = relation.to_object.Title()
terms.append(SimpleVocabulary.createTerm(key, key, label))
return SimpleVocabulary(terms)
开发者ID:pemzurigo,项目名称:opengever.core,代码行数:30,代码来源:vocabulary.py
示例7: __call__
def __call__(self, context):
terms = []
terms.append(SimpleVocabulary.createTerm(u'Darreres activitats', 'darreres_activitats', _(u'Darreres activitats')))
terms.append(SimpleVocabulary.createTerm(u'Activitats mes valorades', 'activitats_mes_valorades', _(u'Activitats mes valorades')))
terms.append(SimpleVocabulary.createTerm(u'Activitats destacades', 'activitats_destacades', _(u'Activitats destacades')))
return SimpleVocabulary(terms)
开发者ID:UPCnet,项目名称:ulearn.core,代码行数:7,代码来源:controlpanel.py
示例8: MetadataVocabulary
def MetadataVocabulary(context):
"""
Metadata name is stored in registry. Format for default name is "fieldname:"
and format for custom name is ":customname"
"""
terms = []
portal = getSite()
metadataDisplay = getToolByName(portal, 'portal_atct').getMetadataDisplay()
for name, display_name in metadataDisplay.items():
if name in ['end', 'EffectiveDate', 'start', 'ExpirationDate', 'ModificationDate', 'CreationDate']:
for format,format_name in [('localshort', 'Date'),('locallong','Date & Time')]:
terms.append(SimpleVocabulary.createTerm("%s:%s"% (name, format), None,
"%s (%s)"%(display_name, format_name)))
elif name in ['Title', 'getId']:
terms.append(SimpleVocabulary.createTerm(name + ":", None, display_name))
for format,format_name in [('tolink', 'Link')]:
terms.append(SimpleVocabulary.createTerm("%s:%s"% (name, format), None,
"%s (%s)"%(display_name, format_name)))
else:
terms.append(SimpleVocabulary.createTerm(name + ":", None, display_name))
# custom field
reg = queryUtility(IRegistry)
if reg is not None:
proxy = ComplexRecordsProxy(reg, IListingCustomFieldControlPanel,
prefix='collective.listingviews.customfield',
key_names={'fields': 'id'})
for field in proxy.fields:
terms.append(SimpleVocabulary.createTerm(':' + field.id, None,
"%s (Custom)" % field.name))
return SimpleVocabulary(terms)
开发者ID:jean,项目名称:collective.listingviews,代码行数:31,代码来源:interfaces.py
示例9: getProfiles
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,代码行数:26,代码来源:vocabularies.py
示例10: __call__
def __call__(self, context):
acl_users = getToolByName(context, 'acl_users')
try:
miColeccion=context.coleccionR[0].to_object
idGAsign=IColecGroupName(miColeccion).groupName
except:
print "No se puedo asignar IColectGroupName"
return SimpleVocabulary([SimpleVocabulary.createTerm("", str(""), "")])
idGPot=idGAsign.replace("_g",PREFIJO_COOR_POTENCIAL)
grupoPot= acl_users.getGroupById(idGPot)
grupoAsignado=acl_users.getGroupById(idGAsign)
terms = []
listIds=[]
if grupoPot is not None:
for member_id in grupoPot.getMemberIds()+grupoAsignado.getMemberIds():
if member_id not in listIds:
user = acl_users.getUserById(member_id)
if user is not None:
member_name = user.getProperty('fullname') or member_id
listIds.append(member_id)
terms.append(SimpleVocabulary.createTerm(member_id, str(member_id), member_name))
return SimpleVocabulary(terms)
#devulve un registro vacio
return SimpleVocabulary([SimpleVocabulary.createTerm("", str(""), "")])
开发者ID:termoHead,项目名称:portal-arcas,代码行数:28,代码来源:vocabularios.py
示例11: availableDonationForms
def availableDonationForms(context):
terms = []
settings = get_settings()
default = settings.default_donation_form
terms.append(SimpleVocabulary.createTerm(default, default,
'Stripe Donation Form'))
try:
campaign_getter = context.get_fundraising_campaign
except AttributeError:
# The campaign hasn't been created yet, so there are no
# available campaign-specific donation forms yet.
pass
else:
campaign = campaign_getter()
query = {
"portal_type": "collective.salesforce.fundraising.productform",
"path": '/'.join(campaign.getPhysicalPath()),
}
pc = getToolByName(context, 'portal_catalog')
res = pc.searchResults(**query)
for form in res:
form_id = form.id + '/donation_form_stripe'
terms.append(
SimpleVocabulary.createTerm(form_id, form_id,
'Product Form: ' + form.Title))
return SimpleVocabulary(terms)
开发者ID:innocenceproject,项目名称:collective.salesforce.fundraising,代码行数:31,代码来源:fundraising_campaign.py
示例12: __call__
def __call__(self,context):
acl_users = getToolByName(context, 'acl_users')
group_list = acl_users.source_groups.getGroups()
terms = [SimpleVocabulary.createTerm('Authenticated Users', 'Authenticated Users', 'Authenticated Users')]
for group in group_list:
terms.append(SimpleVocabulary.createTerm(group.getName(), group.getName() ,group.title or group.getName()))
return SimpleVocabulary(terms)
开发者ID:mamogmx,项目名称:iol.desktop,代码行数:7,代码来源:vocabularies.py
示例13: __call__
def __call__(self, context):
tmp = SimpleVocabulary([
SimpleTerm('one', 'one', u'One'),
SimpleTerm('two', 'two', u'Two'),
SimpleTerm('three', 'three', u'Three'),
])
tmp.test = 1
return tmp
开发者ID:ampsport,项目名称:plone.app.widgets,代码行数:8,代码来源:testing.py
示例14: ViewletsTemplatesVocabFactory
def ViewletsTemplatesVocabFactory(context):
""" Vocabulary for potential vielets renderers listing """
terms = [
SimpleVocabulary.createTerm(name, name, u'%s (%s)' % (name, adapter.title))
for name, adapter in getAdapters((context, context.REQUEST), IViewletResultsRenderer)
]
terms.insert(0, SimpleVocabulary.createTerm('', '', u'None'))
return SimpleVocabulary(terms)
开发者ID:collective,项目名称:collective.viewlet.pythonscript,代码行数:8,代码来源:vocabulary.py
示例15: flattrLanguageVocab
def flattrLanguageVocab(context):
portal = getToolByName(context, "portal_url").getPortalObject()
flattr = getMultiAdapter((portal, context.REQUEST), name="collective_flattr")
languages = flattr.getLanguages()
terms = [SimpleVocabulary.createTerm("sysdefault", "sysdefault", _(u"System default"))]
for lang in languages:
terms.append(SimpleVocabulary.createTerm(lang["id"], lang["id"], lang["text"]))
return SimpleVocabulary(terms)
开发者ID:chrigl,项目名称:docker-library,代码行数:8,代码来源:vocab.py
示例16: __call__
def __call__(self, context):
terms = []
empty = 'Not defined (DEFAULT)'
terms.append(SimpleVocabulary.createTerm(empty, str(empty), empty))
extenders = [a[0] for a in getUtilitiesFor(ICatalogFactory) if a[0].startswith('user_properties') and a[0] != 'user_properties']
for extender in extenders:
terms.append(SimpleVocabulary.createTerm(extender, str(extender), extender))
return SimpleVocabulary(terms)
开发者ID:UPCnet,项目名称:genweb.controlpanel,代码行数:8,代码来源:core.py
示例17: _subscription_field
def _subscription_field(self):
subscription_terms = []
self_subscribed = False
is_really_muted = self.user_is_muted
if is_really_muted:
subscription_terms.insert(0, self._unmute_user_term)
for person in self._subscribers_for_current_user:
if person.id == self.user.id:
if is_really_muted:
# We've already added the unmute option.
continue
else:
if self.user_is_subscribed_directly:
subscription_terms.append(
self._update_subscription_term)
subscription_terms.insert(
0, self._unsubscribe_current_user_term)
self_subscribed = True
else:
subscription_terms.append(
SimpleTerm(
person, person.name,
structured(
'unsubscribe <a href="%s">%s</a> from this bug',
canonical_url(person),
person.displayname).escapedtext))
if not self_subscribed:
if not is_really_muted:
subscription_terms.insert(0,
SimpleTerm(
self.user, self.user.name,
'subscribe me to this bug'))
elif not self.user_is_subscribed_directly:
subscription_terms.insert(0,
SimpleTerm(
'update-subscription', 'update-subscription',
'unmute bug mail from this bug and subscribe me to '
'this bug'))
# Add punctuation to the list of terms.
if len(subscription_terms) > 1:
for term in subscription_terms[:-1]:
term.title += ','
subscription_terms[-2].title += ' or'
subscription_terms[-1].title += '.'
subscription_vocabulary = SimpleVocabulary(subscription_terms)
if self.user_is_subscribed_directly or self.user_is_muted:
default_subscription_value = self._update_subscription_term.value
else:
default_subscription_value = (
subscription_vocabulary.getTermByToken(self.user.name).value)
subscription_field = Choice(
__name__='subscription', title=_("Subscription options"),
vocabulary=subscription_vocabulary, required=True,
default=default_subscription_value)
return subscription_field
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:58,代码来源:bugsubscription.py
示例18: getWebProperties
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,代码行数:56,代码来源:vocabularies.py
示例19: __call__
def __call__(self, context, query=None):
items = [u'One', u'Two', u'Three']
tmp = SimpleVocabulary([
SimpleTerm(it.lower(), it.lower(), it)
for it in items
if query is None or
query.lower() in it.lower()
])
tmp.test = 1
return tmp
开发者ID:upiq,项目名称:plone.app.z3cform,代码行数:10,代码来源:test_widgets.py
示例20: if_not_found_list
def if_not_found_list(context):
terms = [SimpleVocabulary.createTerm('__ignore__', '__ignore__', 'Skip'),
SimpleVocabulary.createTerm('__stop__', '__stop__', 'Stop')]
for fti in get_allowed_types(context):
portal_type = fti.getId()
terms.append(SimpleVocabulary.createTerm(portal_type, portal_type,
"Create %s" % fti.title))
return SimpleVocabulary(terms)
开发者ID:collective,项目名称:collective.importexport,代码行数:10,代码来源:import_view.py
注:本文中的zope.schema.vocabulary.SimpleVocabulary类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论