23 lines
631 B
Python
23 lines
631 B
Python
"""
|
|
common utilities
|
|
"""
|
|
|
|
from zope.schema import vocabulary
|
|
|
|
|
|
class KeywordVocabulary(vocabulary.SimpleVocabulary):
|
|
|
|
def __init__(self, items, *interfaces):
|
|
""" ``items`` may be a tuple of (token, title) or a dictionary
|
|
with corresponding elements named 'token' and 'title'.
|
|
"""
|
|
terms = []
|
|
for t in items:
|
|
if type(t) is dict:
|
|
token, title = t['token'], t['title']
|
|
else:
|
|
token, title = t
|
|
terms.append(vocabulary.SimpleTerm(token, token, title))
|
|
super(KeywordVocabulary, self).__init__(terms, *interfaces)
|
|
|
|
|