[Grok-dev] Vocabulary registration
darryl at darrylcousins.net.nz
Mon Mar 12 20:32:22 EDT 2007
I'm struggling a little here registering a vocabulary for use in a form.
I'm reusing code that I'd previously used and trying to twig it to work
I can easily register a vocabulary as a global utility:
"""Returns the vocabulary for a choice field of available languages
on the context"""
def __call__(self, context):
name=u'I18n Context Languages')
And I can get the utility as expected:
>>> rock = I18nRock(title=u'I wish I were a rock')
u'I wish I were a rock'
>>> rock.addLanguage('de',title=u'Ich bin ein Stein')
u'Ich bin ein Stein'
>>> from zope.schema.interfaces import IVocabularyFactory
>>> vocab = component.getUtility(IVocabularyFactory, name='I18n
>>> [t.token for t in vocab(rock)]
But when I call for the i18neditform (which uses the vocabulary):
>>> request = TestRequest()
>>> from zope import component
>>> view = component.getMultiAdapter((rock, request), name='edit')()
Traceback (most recent call last):
VocabularyRegistryError: unknown vocabulary: u'I18n Context
So vocabularies registered as global utilities are not available in the
Vocabulary registry. This may be normal?
I'll go on to try setting up a root Application object and registering
the vocabulary as a local_utility to see if I can get to it that way.
More information about the Grok-dev