Advertisement
Guest User

vocabularies/example_vocabulary.py

a guest
Jan 22nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. from plone import api
  2. from zope.interface import implementer
  3. from zope.schema.interfaces import IVocabularyFactory
  4. from zope.schema.vocabulary import SimpleTerm
  5. from zope.schema.vocabulary import SimpleVocabulary
  6.  
  7.  
  8. @implementer(IVocabularyFactory)
  9. class ExampleVocabularyVocabulary(object):
  10.     """
  11.    """
  12.  
  13.     def __call__(self, context):
  14.         # as an example we create a vocabulary of all News Items items in the portal:
  15.         items = [
  16.             VocabItem(u'sony-a7r-iii', _(u'Sony Aplha 7R III')),
  17.             VocabItem(u'canon-5d-iv', _(u'Canon 5D IV')),
  18.         ]
  19.  
  20.         # create a list of SimpleTerm items:
  21.         terms = []
  22.         for item in items:
  23.             terms.append(
  24.                 SimpleTerm(
  25.                     value=item.token,
  26.                     token=str(item.token),
  27.                     title=item.value,
  28.                 )
  29.             )
  30.         return SimpleVocabulary(terms)
  31.  
  32.  
  33. ExampleVocabularyVocabularyFactory = ExampleVocabularyVocabulary()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement