[Zope3-dev] Creating a resource: Presentation service not available

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Oct 6 07:15:55 EDT 2004


On Tuesday 05 October 2004 21:26, Peter Mayne wrote:
> I've written a resource that provides a dynamic image capability, useful
> for presenting charts and so on. The catch is that I'm not sure
> where/when to register it.
>
> The registration code I use is:
>
>      factory = MyResourceFactory(...)
>      gps = sm.getService(Presentation)
>      gps.provideAdapter(IBrowserRequest, factory, name='my.png',
> layer='default')

You should **never** register something like this using Python code. Also, you 
should avoid calling the presentation service directly; it is already removed 
in the trunk. (You might have no choice in this case, since the resource 
directive is not flexible enough).

> If I run this code at the end of one of my class files, I get:
>
>    File
> "/tmp/ZopeX3-3.0.0c2/build/lib.linux-i686-2.3/zope/component/service.py",
> line 109, in getService
>     raise ComponentLookupError: 'Presentation'
>
> presumably because the Presentation service isn't defined yet.

Yep. You have to do this via a directive.

> How can I get my resource registration code to run after the
> Presentation service is available, and before Z3 has finished starting?

Implement a directive similar to the `browser:resource` directive. When you 
use the directive, the services will all be up and running.

It is a pitty that the resource directive currently does not allow you to 
specify a factory, which it should, because then you could just reuse the 
resource directive directly. Please make an issue report in this regard and I 
will implement that feature for 3.1.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-dev mailing list