[Grok-dev] Re: distinction between adapts() and context()

Philipp von Weitershausen philipp at weitershausen.de
Wed Mar 19 05:41:51 EDT 2008

Brandon Craig Rhodes wrote:
> Why does the AdapterGrokker() in grok/meta.py look only for a
> grok.context() declaration on an adapter, and not pay any attention to
> native Zope .adapts() information on the class?

Mostly because of symmetry. 'grok.context' always specifies what kind of 
an object 'self.context' will be, on both views, adapters, etc.

> I think it would be
> nice if it accepted either directive, but I wanted to ask and find out
> if it was omitted on purpose for some reason I'm not thinking of this
> late at night. :-)

I suppose it could *also* allow z.c.adapts() if it can't find a 
grok.context() directive.

> It has always felt to me as though grok.context() is basically a
> synonym for grok.adapts(),

Yes and no. On 1-ary adapters, they are. On views, grok.context just 
specifies what 'self.context' will be, not what (self.context, 
self.request) will be.

> but one that's named so that we can hide
> from people just writing Views the big concept that they're actually
> writing a well-known object-oriented design pattern in order to suit
> their objects up for the web.

More information about the Grok-dev mailing list