[Grok-dev] Re: Getting a view from within a REST layer

Peter Bengtsson peter at fry-it.com
Tue Dec 11 06:31:42 EST 2007



Jan-Wijbrand Kolman wrote:
> Hi Peter,
> 
> Peter Bengtsson wrote:
>> getMultiAdapter((context, request), name="Nameofview")
>> doesn't work inside my REST layer which I built thanks to this tutorial:
>> http://grok.zope.org/minitutorials/rest.html
>>
>> This is the error I get:
>>     raise ComponentLookupError(objects, interface, name)
>> ComponentLookupError: ((<snapatom.app.snapatom object at 0x8b7f6ac>,
>> <InterfaceClass zope.interface.Interface>), <InterfaceClass
>> zope.interface.Interface>, 'bloglist')
> 
> snip
> 
>> Am I doing it completely wrong or is it a bug?
>> I basically want to render a view and spit out its result in the method
>> GET() of my REST layer.
> 
> The thing I do not really understand about the error message you get is,
> that getMultiAdapter() is looking for a component adapting the
> combination of <snapatom.app.snapatom> and <zope.interface.Interface>...
> somehow the request object you obtain seems not to provide any useful
> interface for the lookup.
> 

Crap! I paste that in. Using Interface instead of self.request was just 
something I tested that didn't work either.
Originally, and what caused the above error, was:
getMultiAdapter((self.context, self.request), name="bloglist")

I suspect that it's something I haven't understood about layers and 
skins (don't even know the difference between the two). Perhaps you're 
not meant to do too much inside the layer but instead just capture the 
request there and immediately do the coding in the application context 
(class snapatom is my case).


> A wild guess, but what happens if you do:
> 
>   from zope.interface import alsoProvides
> 
>   class MyREST(grok.REST):
>     grok.layer(AtomPubLayer)
>     grok.context(snapatom)
> 
>     def GET(self):
>         # ugly hack to test the lookup
> 	alsoProvides(request, IBrowserRequest)
>         view = getMultiAdapter((context, request), name="bloglist")
>         return view()
> 
> Mind though, even if this does work, it is basically "lying" to the
> component system - I would have guessed too that the request object you
> get in the REST context could be used for view lookups. But the REST
> stuff is a bit misty to me...
> 
> 
> HTH
> kind regards,
> jw
> 
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
> 

-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Grok-dev mailing list