[Grok-dev] registering vocabulary
Paolo Piersanti
paolo at micso.it
Thu Apr 14 03:53:51 EDT 2011
On 04/13/2011 06:29 PM, Christian Klinger wrote:
> Hi Paolo,
>
> can you paste the traceback of the error.
>
> And how you registerd the utility?
Hi Christian
I registered the vocabulary as
grok.global_utility(WidgetTypeVocabulary,name=u"widget_type_vocabulary")
and it works fine when I do
getUtility(WidgetTypeVocabulary, name=u"widget_type_vocabulary")
I can get my utility.
The utility is implemented in this way:
class WidgetTypeVocabulary(object):
grok.implements(IVocabularyFactory)
def __call__(self, context):
values = (....)
return SimpleVocabulary.fromItems(values)
I also use it in a form interface as
class IStatement(interface.Interface):
widget_type = schema.Choice(title=_(u"Widget Type"),
description=_(u"Widget Type"),
vocabulary=u'widget_type_vocabulary',
required=True)
but here the exception is triggered when the grok machinery
try to instantiate the form involved in the add or edit actions
here is the traceback:
> Traceback (most recent call last):
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.publisher-3.12.6-py2.6.egg/zope/publisher/publish.py", line 132, in publish
> result = publication.callObject(request, obj)
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/grokcore.view-2.5-py2.6.egg/grokcore/view/publication.py", line 56, in callObject
> return super(ZopePublicationSansProxy, self).callObject(request, ob)
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.app.publication-3.13.1-py2.6.egg/zope/app/publication/zopepublication.py", line 207, in callObject
> return mapply(ob, request.getPositionalArguments(), request)
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.publisher-3.12.6-py2.6.egg/zope/publisher/publish.py", line 107, in mapply
> return debug_call(obj, args)
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.publisher-3.12.6-py2.6.egg/zope/publisher/publish.py", line 113, in debug_call
> return obj(*args)
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/grokcore.formlib-1.8-py2.6.egg/grokcore/formlib/components.py", line 90, in __call__
> self.update_form()
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/grokcore.formlib-1.8-py2.6.egg/grokcore/formlib/components.py", line 62, in update_form
> super(GrokForm, self).update()
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.formlib-4.0.5-py2.6.egg/zope/formlib/form.py", line 758, in update
> self.setUpWidgets()
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.formlib-4.0.5-py2.6.egg/zope/formlib/form.py", line 833, in setUpWidgets
> adapters=self.adapters, ignore_request=ignore_request
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.formlib-4.0.5-py2.6.egg/zope/formlib/form.py", line 388, in setUpEditWidgets
> field = field.bind(adapter)
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.schema-3.7.1-py2.6.egg/zope/schema/_field.py", line 291, in bind
> clone.vocabulary = vr.get(object, self.vocabularyName)
> File "/home/gon/src/crm_campaign_env/crm_campaign/eggs/zope.schema-3.7.1-py2.6.egg/zope/schema/vocabulary.py", line 166, in get
> raise VocabularyRegistryError(name)
> VocabularyRegistryError: unknown vocabulary: u'widget_type_vocabulary'
Inspectioning the vocabulary registry with pdb results in a failing
lookup.
Registering the vocabulary in this way:
>from zope.schema.vocabulary import getVocabularyRegistry
>getVocabularyRegistry().register(u'widget_type_vocabulary',
>
WidgetTypeVocabulary())
everything is ok.
Thank you for your support
Paolo Piersanti
--
Signature for Rent - Questo spazio si affitta
Paolo Piersanti Software Developer & System Admininistrator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5998 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20110414/17969074/attachment.bin
More information about the Grok-dev
mailing list