[Grok-dev] Querying the CA for grok'ed Views

Kevin Teague kevin at bud.ca
Thu Mar 26 15:00:15 EDT 2009

I'm wondering if anyone has used the CA to query for Views to support
building navigational elements? Or has written any code for inspecting/
browsing the contents of the CA?

I'd like to be able to get a listing of all Views registered for a
particular interface or class. But I'm not sure how to do that. What I
have so far:

import grok
import zope.component
import zope.publisher.interfaces.browser
import zope.interface

class IViewiface(zope.interface.Interface):

class Viewiface(grok.Application, grok.Container):

class Index(grok.View):

    def all(self):
        gsm = zope.component.getGlobalSiteManager()
        return gsm.adapters.lookupAll(

Which shows me that there is an assorted collection of generic Views
registered, but doesn't get me the 'index' View for Viewiface. If I
iterate through all adapters (using gsm._adapter_registrations) I see:

(<implementedBy viewiface.app.Viewiface>, <InterfaceClass
<InterfaceClass zope.interface.Interface>

But I can't figure out how to query the adapter registry for class
registrations (e.g. implementedBy). Is this possible?

Secondly, if I can query the adapter registry for a list of all Views
for Viewiface, I will want to filter that list down to just Grok Views
(e.g. adapting to grok.interfaces.IGrokView). It doesn't seem like
when a View is grokked that it registers the view as adapting to
IGrokView, but instead registers it for the generic
zope.interface.Interface. Is there a reason for this? Wouldn't it be
more accurate (and helpful) if it was registered for IGrokView?

Thirdly, if someone writes a kick-ass "CA browser" that showed you all
registrations and let you search for specific ones, and add it to
grokui.admin, that would be awesome :)

More information about the Grok-dev mailing list