[Zope3-dev] Re: Creating a resource: Presentation service not
available
Peter Mayne
PeterMayne at ap.spherion.com
Tue Oct 19 02:46:15 EDT 2004
Stephan Richter wrote:
> 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.
I've (finally) put this into a directive definition to create my own
<browser:registerMe> directive.
The directive itself seems to be working fine, but when I execute the
above registration code in the handler, I still get
"ComponentLookupError: 'Presentation'". The same code still works fine
if I run it after Z3 has started up. This implies that the Presentation
service isn't running when my directive is used.
Given that the Presentation service is going/has gone away, what is the
right way to register my resource?
Thanks.
PJDM
--
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit
More information about the Zope3-dev
mailing list