[Grok-dev] Simple adapter question
Jan Ulrich Hasecke
juhasecke at googlemail.com
Thu Mar 5 14:41:10 EST 2009
-----BEGIN PGP SIGNED MESSAGE-----
Am 05.03.2009 um 20:26 schrieb Martin Aspeli:
>>> import grok
>>> from zope import interface
>>> class Fireplace(grok.Model):
>>> class Cave(grok.Model):
>>> class IHome(interface.Interface):
>>> class Home(grok.MultiAdapter):
>>> grok.adapts(Cave, Fireplace)
>>> def __init__(self, cave, fireplace):
>>> self.cave = cave
>>> self.fireplace = fireplace
>>> home = IHome(cave, fireplace)
> This looks fishy to me. Unless Grok is doing something very evil, this
> won't work: it'll try to adapt `cave` to IHome, and if that fails,
> fall back to the second argument 'fireplace'.
> I think what you want is:
> home = getMultiAdapter((cave, fireplace), IHome)
>>> Why is there an IHome in the last line? I would think that
>>> home = Home(cave, fireplace)
>>> would create a home-instance.
> It does, and in this case, the two are probably equivalent. "Calling"
> the interface (for a single-adapter!) or using
> getAdapter/getMultiAdapter, means "Get the adapter from what I give
> to the interface I ask for". If there was a more specific adapter to
> IHome, then you'd get that one instead.
So why the class Home is defined at all?
> If you can, find Brandon Craig Rhodes "using grok to walk like a duck"
> talk on video and watch it. :)
I presume that I miss something obvious to everyone else, so I'll
watch the film again. It is really great.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (Darwin)
-----END PGP SIGNATURE-----
More information about the Grok-dev