本文整理汇总了Python中zope.schema.vocabulary.SimpleVocabulary类的典型用法代码示例。如果您正苦于以下问题:Python SimpleVocabulary类的具体用法?Python SimpleVocabulary怎么用?Python SimpleVocabulary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleVocabulary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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()]
示例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]
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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(""), "")])
示例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)
示例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)
示例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
示例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)
示例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)