Re: [Zope3-dev] Re: Get a template resource object from code.

2005-08-28 Thread Stephan Richter
Hi Johan,

why are you trying to misuse the system so hard? Can you provide us with your 
original use case?

On Tuesday 16 August 2005 18:23, Johan Carlsson wrote:
 1. Resources gets registered as adapters in the Global Site Manager.

Yep.

 2. The adapter is registerd to adapt from the current layer interface
 (defaults to IDefaultBrowserLayer) to the Interface interface (strange,
 why is that so I wounder?)

The Interface interface is just the default. Sometimes you want views to 
provide other interfaces.

 3. The layer interface I can look up byt calling:
 zapi.getUtility(ILayer, 'my_layer')

 Ok, fine. So from my View class I try the following:

          gsm=zapi.getGlobalSiteManager()
          layer = zapi.getUtility(ILayer, 'my_test')
          adapter=gsm.queryAdapter(layer, Interface, 'test_me.html')

This will not work, because layer is the actual layer interface. However, 
queryAdapter expects an object that provides the layer interface. This object 
is usually known as the request.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics  Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: Get a template resource object from code.

2005-08-16 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Johan Carlsson wrote:
 
 No lock on the Zope3-users list I turn here.
 
 How do I get a page template resource object define in a named layer
 from Python code?

Look at what the handler for the browser:resource directive does:

  zope.app.component.metaconfigure.resource


Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   Excellence by Designhttp://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDAmCx+gerLs4ltQ4RArQsAJ9m+wLLLPCbtKVs69mCNQOqThUXmwCbBC/w
K2U/5EIkHF+2FOM81mmHTTI=
=RMAC
-END PGP SIGNATURE-

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: Get a template resource object from code.

2005-08-16 Thread Johan Carlsson

Tres Seaver wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Johan Carlsson wrote:


No lock on the Zope3-users list I turn here.

How do I get a page template resource object define in a named layer
from Python code?



Look at what the handler for the browser:resource directive does:

  zope.app.component.metaconfigure.resource


Thanks Tres,
Already done that. It registers the resource as an adapter on the global 
site manger. Problem is I can't get the adapter, but gets an error.
The registration is somewhat strange in it self (adapts from layer 
interface to Interface interface???).


I cut and paste my post from the Zope3-users list:


Ok, so far I figured out the following:

1. Resources gets registered as adapters in the Global Site Manager.
2. The adapter is registerd to adapt from the current layer interface 
(defaults to IDefaultBrowserLayer) to the Interface interface (strange, 
why is that so I wounder?)
3. The layer interface I can look up byt calling: 
zapi.getUtility(ILayer, 'my_layer')


Ok, fine. So from my View class I try the following:

gsm=zapi.getGlobalSiteManager()
layer = zapi.getUtility(ILayer, 'my_test')
adapter=gsm.queryAdapter(layer, Interface, 'test_me.html')


But this doesn't work, I get the following error:


Error type: exceptions.KeyError
Error object: weakref at 02545900; to 'Surrogate' at 0210CAF0

File C:\Python24\Lib\site-packages\zope\publisher\publish.py, line 
138, in publish


File 
C:\Python24\Lib\site-packages\zope\app\publication\zopepublication.py, 
line 164, in callObject


File C:\Python24\Lib\site-packages\zope\publisher\publish.py, line 
113, in mapply


File C:\Python24\Lib\site-packages\zope\publisher\publish.py, line 
119, in debug_call


File C:\Zope\Zope31\lib\python\wfc\browser\metasite.py, line 44, in 
__call__

adapter=gsm.queryAdapter(layer, Interface, 'test_me.html')

File C:\Python24\Lib\site-packages\zope\component\site.py, line 70, in 
queryAdapter

Set all module' __file__ attribute to an absolute path

File C:\Zope\Zope31\lib\python\zope\interface\adapter.py, line 414, in 
queryAdapter

return self.adapter_hook(interface, object, name, default)

File C:\Zope\Zope31\lib\python\zope\interface\adapter.py, line 404, in 
adapter_hook

factory = self.lookup1(providedBy(object), interface, name)

File C:\Zope\Zope31\lib\python\zope\interface\adapter.py, line 392, in 
lookup1

return self.lookup((required,), provided, name, default)

File C:\Zope\Zope31\lib\python\zope\interface\adapter.py, line 327, in 
lookup

byname = s.get(provided)

File C:\Zope\Zope31\lib\python\zope\interface\adapter.py, line 227, in get
self.clean()

File C:\Zope\Zope31\lib\python\zope\interface\adapter.py, line 146, in 
clean

base.unsubscribe(self)

File C:\Zope\Zope31\lib\python\zope\interface\adapter.py, line 248, in 
unsubscribe

del self.dependents[dependent]

File C:\Python24\lib\weakref.py, line 216, in __delitem__
del self.data[ref(key)]


Can somebody sched a light on this problem?

Regards,
Johan


--
Johan Carlsson  Tel: + 46 8 31 24 94
Colliberty  Mob: + 46 70 558 25 24
Torsgatan 72Email: [EMAIL PROTECTED]
SE-113 37 STOCKHOLM

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com