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

Souheil CHELFOUH trollfot at gmail.com
Thu Mar 26 16:58:25 EDT 2009

It's the zope default to register a view as providing Interface.
I often complained about that, since it would be interesting to be
able to do a : getAdapters((context, request), IProvidedIface)
I did that on a project, but had to code my very own grokker.
This is a bit silly, I think that the grok.provide() should be
possibly overriding that base behavior.

Looking up through all the registry might be performance costy, though.

about class query :


2009/3/26 Kevin Teague <kevin at bud.ca>:
> 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):
>    pass
> class Viewiface(grok.Application, grok.Container):
>    grok.implements(IViewiface)
> class Index(grok.View):
>    def all(self):
>        gsm = zope.component.getGlobalSiteManager()
>        return gsm.adapters.lookupAll(
>            (
>                zope.interface.Interface,
> zope.publisher.interfaces.browser.IDefaultBrowserLayer,
>            ),
>            zope.interface.Interface
>        )
> 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
> zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
> <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 :)
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev

More information about the Grok-dev mailing list