本文整理汇总了Python中zope.schema.interfaces.ITitledTokenizedTerm.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python ITitledTokenizedTerm.providedBy方法的具体用法?Python ITitledTokenizedTerm.providedBy怎么用?Python ITitledTokenizedTerm.providedBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.schema.interfaces.ITitledTokenizedTerm
的用法示例。
在下文中一共展示了ITitledTokenizedTerm.providedBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: items
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def items(self):
items = []
if self.terms is not None:
# update() has been called
if ((not self.required or self.prompt)
and not bool(self.multiple)):
message = self.noValueMessage
if self.prompt:
message = self.promptMessage
items.append({
'id': self.id + '-novalue',
'value': self.noValueToken,
'content': message,
'selected': self.value == []
})
for count, term in enumerate(self.terms):
selected = self.isSelected(term)
id = '%s-%i' % (self.id, count)
content = term.token
if ITitledTokenizedTerm.providedBy(term):
content = translate(
term.title,
context=self.request,
default=term.title)
items.append(
{'id':id,
'value':term.token,
'content':content,
'selected':selected})
return items
示例2: test_get_term_by_token
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def test_get_term_by_token(self):
# we can get a term by its token
source = RedisAutocompleteSource(
host=self.redis_host, port=self.redis_port,
zset_name="autocomplete-foo")
result = source.getTermByToken(u'1')
self.assertTrue(ITitledTokenizedTerm.providedBy(result))
示例3: cmp
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def cmp(self, term, query):
# ajax search widget does a search on this vocabulary,
# if we have titled terms, we have to compare against the title
# otherwise use the value.
if ITitledTokenizedTerm.providedBy(term):
return query in term.title.lower()
return query in term.value.lower()
示例4: items
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def items(self):
# TODO: check if we should cache the return list
if self.terms is None: # update() not yet called
return ()
vocab = getUtility(
IVocabularyFactory, "org.bccvl.site.algorithm_category_vocab")(self.context)
items = OrderedDict((cat.value, [])
for cat in chain((SimpleTerm(None),), vocab))
for count, term in enumerate(self.terms):
alg = term.brain.getObject()
# skip algorithm without category
# if alg.algorithm_category is None or alg.algorithm_category not in items:
# continue
itemList = items[alg.algorithm_category]
checked = self.isChecked(term)
id = '%s-%i' % (self.id, count)
if ITitledTokenizedTerm.providedBy(term):
label = translate(
term.title, context=self.request, default=term.title)
else:
label = util.toUnicode(term.value)
catterm = SimpleTerm(None)
if alg.algorithm_category in vocab:
catterm = vocab.getTerm(alg.algorithm_category)
itemList.append({'id': id, 'name': self.name + ':list', 'value': term.token,
'label': label, 'checked': checked,
'subject': term.brain.Subject,
'description': term.brain.Description,
'category': catterm,
'pos': len(itemList)})
return items.values()
示例5: users
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def users(self):
context = self.context
memtool = getToolByName(context, 'portal_membership')
vocabulary = queryUtility(schema.interfaces.IVocabularyFactory,
name='ftw.notification.base.users',
context=context)
if vocabulary:
users = vocabulary(context)
finalized = []
for t in users:
userid = t.value
member = memtool.getMemberById(userid)
if member is None:
continue
title = t.title if ITitledTokenizedTerm.providedBy(t) else t.value
user = dict(title=title,
value=t.value,
email=member.getProperty("email", ""),
selected=t.value in self.pre_select)
finalized.append(user)
finalized.sort(key=lambda user: user['title'].lower())
return finalized
示例6: test_iter
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def test_iter(self):
# we can iterate over all elements
source = RedisAutocompleteSource(
host=self.redis_host, port=self.redis_port,
zset_name="autocomplete-foo")
elem_list = [x for x in source]
self.assertEqual(len(elem_list), 4)
self.assertTrue(ITitledTokenizedTerm.providedBy(elem_list[0]))
示例7: render_default_title
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def render_default_title(self, item, value):
"""Render the default title colum with the term's title."""
term = self.terms.getTerm(item)
if ITitledTokenizedTerm.providedBy(term):
label = translate(term.title, context=self.request,
default=term.title)
else:
label = util.toUnicode(term.value)
return label
示例8: test_get_term_contained
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def test_get_term_contained(self):
# we can get contained terms as ITerm
source = RedisSource(host=self.redis_host, port=self.redis_port)
term = source.getTerm(u'foo')
assert ITitledTokenizedTerm.providedBy(term)
self.assertTrue(hasattr(term, 'value'))
self.assertEqual(term.value, u'foo')
self.assertTrue(hasattr(term, 'token'))
self.assertEqual(term.token, 'Zm9v')
self.assertTrue(hasattr(term, 'title'))
self.assertEqual(term.title, u'bar')
示例9: addItem
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def addItem(idx, group, term, prefix=''):
selected = self.isSelected(term)
if selected:
ignored.remove(term.token)
id = '%s-%s%i' % (self.id, prefix, idx)
content = term.token
if ITitledTokenizedTerm.providedBy(term):
content = translate(
term.title, context=self.request, default=term.title)
optgroups[group].append(
{'id': id, 'value': term.token, 'content': content,
'selected': selected})
示例10: render_default_title
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def render_default_title(self, item, value):
"""Render the default title colum with the term's title."""
if isinstance(item, NullObject):
return _(u'label_none', default=u'None')
term = self.terms.getTerm(item)
if ITitledTokenizedTerm.providedBy(term):
label = translate(term.title, context=self.request,
default=term.title)
else:
label = util.toUnicode(term.value)
return label
示例11: textForValue
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def textForValue(self, term):
"""Extract a string from the `term`.
The `term` must be a vocabulary tokenized term.
This can be overridden to support more complex `term`
objects. The token is returned here since it's the only thing
known to be a string, or str()able.
"""
if ITitledTokenizedTerm.providedBy(term):
return self.translate(term.title)
return term.token
示例12: items
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def items(self):
if self.terms is None: # update() has not been called yet
return ()
items = []
if self.multiple is None:
message = self.noValueMessage
if self.prompt:
message = self.promptMessage
items.append({
'id': self.id + '-novalue',
'value': self.noValueToken,
'content': message,
'selected': self.value == []
})
unordered_items = {}
optgroups = []
for count, term in enumerate(self.terms):
# Exctract optgroups in an ordered list, so we can use this to
# preserve the main order of optgroups.
if not term.optgroup in optgroups:
optgroups.append(term.optgroup)
selected = self.isSelected(term)
id = '%s-%i' % (self.id, count)
content = term.title
if ITitledTokenizedTerm.providedBy(term):
content = self.getContent(term)
if not term.optgroup in unordered_items:
unordered_items[term.optgroup] = []
unordered_items[term.optgroup].append({
'id': id,
'value': term.token,
'content': content,
'selected': selected,
})
for group in optgroups:
if not group:
for ding in unordered_items[group]:
items.append({
'id': ding['id'],
'value': ding['value'],
'content': ding['content'],
'selected': ding['value'] == []
})
else:
item = {}
item['title'] = group
item['member'] = unordered_items[group]
items.append(item)
self.getSize(items)
return items
示例13: _overrideValue
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def _overrideValue(self, widget, value):
if value:
widget.value = ['selected']
widget.items = []
for count, term in enumerate(widget.terms):
checked = widget.isChecked(term)
id = '%s-%i' % (widget.id, count)
label = term.token
if ITitledTokenizedTerm.providedBy(term):
label = translate(term.title, context=widget.request,
default=term.title)
widget.items.append({'id': id, 'name': widget.name + ':list',
'value': term.token, 'label': label, 'checked': checked})
示例14: displayValue
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def displayValue(self):
value = {}
for token in self.value:
# Ignore no value entries. They are in the request only.
if token == self.noValueToken:
continue
term = self.terms.getTermByToken(token)
if ITitledTokenizedTerm.providedBy(term):
content = self.getContent(term)
else:
value.append(term.value)
if not term.optgroup in value:
value[term.optgroup] = []
value[term.optgroup].append(content)
return value
示例15: items
# 需要导入模块: from zope.schema.interfaces import ITitledTokenizedTerm [as 别名]
# 或者: from zope.schema.interfaces.ITitledTokenizedTerm import providedBy [as 别名]
def items(self):
# TODO: check if we should cache the return list
if self.terms is None: # update() not yet called
return ()
items = []
for count, term in enumerate(self.terms):
checked = self.isChecked(term)
id = '%s-%i' % (self.id, count)
if ITitledTokenizedTerm.providedBy(term):
label = translate(term.title, context=self.request,
default=term.title)
else:
label = util.toUnicode(term.value)
items.append ({'id': id, 'name': self.name + ':list', 'value':term.token,
'label':label, 'checked': checked,
'subject': term.brain.Subject})
return items