[Zope-CMF] problems rendering ZPT in Python Script

Grégoire Weber gregoire.weber@switzerland.org
Mon, 13 May 2002 17:35:14 +0200


Hi Tres,
hi all,

oups, that was fast! :-)

I found what I have to do to solve the problem (use 'context' instead of 
'container' in getattr):

  obj = getattr(context, '%s%s' % (context.template_name, '_anon'))
  html = obj() # works!!!

But I do not really understand why it does not work with 'container'.

Especially after reading the following lines in 
http://www.zope.org/Documentation/ZopeBook/ScriptingZope.stx:

   [...]
   Context 
      The Context binding defaults to the name context. This variable 
      refers to the object that the script is called on. 
   Container 
      The Container binding defaults to the name container. This 
      variable refers to the folder that the script is defined in. 
   [...]

I suppose that the reason is somehow related to the skin functionality
of the CMF. Taking 'context' should not be a problem because it finds the
correct ZPT going through the skin path as normal.

If somebody has a explanation I'll write a small receipe in zopelab.

Greetings, Greg

P.S.: Printing obj.aq_chain produces an error (obj.aq_chain() also).

P.P.S.: 'container.topic_view_body_anon' doesn't work neither, so the 
        behaviour is at least the same.

At 10:50 13.05.2002 -0400, Tres Seaver wrote:
>On Mon, 2002-05-13 at 10:33, Grégoire Weber wrote:
>> Hi,
>> 
>> I wanted to return a rendered ZPT by a Python Script. The result was a 
>> bit confusing to me. The skin folder contains a Python Script named 
>> 'topic_view' and a ZPT named 'topic_view_body_anon'.
>> 
>> I searched the mailing list and the http://www.zopelabs.com but didn't
>> find a answer.
>> 
>> I get an error if I do:
>> 
>>    obj = getattr(container, '%s%s' % (context.template_name, '_anon'))
>>    html = obj()
>> 
>> 
>> an no error (thus the rendered page) if I do:
>> 
>>    obj  = context.topic_view_body_anon
>>    html = obj()
>> 
>> What is confusing me is that both 'obj' reference the same object
>> (e.g. <ZopePageTemplate instance at 01701898>).
>> 
>> What's going on?
>> 
>> Any pointers?
>
>You might try looking at the 'aq_chain' attribute of each 'obj';
>sometimes the same "base" object might be wrapped differently.
>OTOH, I have no idea why 'getattr' would wrap the object any
>differently than 'dotted' access.
>
>Tres.
>-- 
>==========================
======================================
>Tres Seaver                                tseaver@zope.com
>Zope Corporation      "Zope Dealers"       http://www.zope.com

_____________________________________
Grégoire Weber
Rigistr. 31
CH-8006 Zürich
Switzerland
phone:  +41-(0)1-361 66 11
mobile: +41-(0)79-44 11 457
mailto:gregoire.weber@switzerland.org