[Grok-dev] Re: distinction between adapts() and context()
Martijn Faassen
faassen at startifact.com
Thu Mar 20 14:48:30 EDT 2008
Philipp von Weitershausen wrote:
> 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.
And give an error if it finds both.
I'd be +1 on the following behavior:
* also accept grok.adapts(), just like we accept it with MultiAdapter
(we do, right?)
* if grok.context() and grok.adapts() are both present, Grok will refuse
to guess and the grokking process stops with a GrokError.
Note that I think this means that you could use grok.Adapter as a
multi-adapter too then: you'd just have to write your own __init__ (just
as for MultiAdapter). Hmm... We could consider disallowing grok.adapts()
to have more than one argument on plain adapters for now. We could
consider getting more permissive in the future and let grok.Adapter take
on the role of grok.MultiAdapter too, but I think we should one step at
the time for this.
I wonder whether this should then also be supported for View - i.e. you
can either use grok.context or explicitly point to context object and
request both. What about viewlets? I'd say let's explictly *not* support
grok.adapts on the view stuff, at least until someone can make a good
case to do so. I'd be +1 for a change that makes this explicit and
always bails out with an error if it finds adapts() on a view or viewlet.
Regards,
Martijn
More information about the Grok-dev
mailing list