[Zope] ZCatalog of method output

Tres Seaver tseaver@palladion.com
Sat, 01 Apr 2000 16:36:17 -0600


"Rik Hoekstra" <rik.hoekstra@inghist.nl>
> 
> -----Original Message-----
> From: Loren Stafford <lstafford@icompression.com>
> To: zope@zope.org <zope@zope.org>
> Date: vrijdag 31 maart 2000 23:03
> Subject: [Zope] ZCatalog of method output
> 
> >I read you could define a ZClass instance's method as a field-index of a
> >ZCatalog; but it's not working for me.
> >
> >The DTML method dept_code is simply:
> >
> >  <dtml-return "_.string.split(jobcode,'-')[0]">
> >
> >When I call the method directly it returns a single character, the first
> >character of the jobcode.
> >
> >The method dept_code is defined as a field-index of the ZCatalog JobsCat.
> >But when I access JobsCat thus:
> >
> > <dtml-in "JobsCat(meta_type='Job Opening', sort_on='dept_code')">
> >   <li>
> >   <a href="<dtml-var "JobsCat.getpath(data_record_id_)">">
> >            (<dtml-var dept_code>) <dtml-var jobcode>: <dtml-var title></a>
> > </dtml-in>
> >
> >the items are not sorted, and dept_code is null.
> >
> >Can anyone see what I'm doing wrong?
> 
> As I understood it (but I may be wrong, cause I never understood why), a
> DTML method in a field index is only usable if it doesn't contain any
> variables anything, that is only if it contains only static values (like
> <dtml-return "'1,2,3,4'"> for example. If you want something executed as a
> property - use either an External Method or a Python Method.
> It was something about the Catalog not being able to feed arguments to a
> method, but I'd be glad if someone could explain this...

When the catalog is calling your method, it does not have access to the
DTML namespace stack, and so cannot pass through the parameters which all
DTMLMethods expect:  client, namespace, and REQUEST.  Therefore, you can only
catalog DTMLMethods in meta_data if they don't require any access to your
object.  The algorithm looks something like:

 1. Check for attribute 'foo'.  If object 'obj' doesn't have one, exit.

 2. If the attribute is callable, then call it, passing 'obj' as the
    first (and only) paramter (i.e., 'foo( obj )' ) to get the value.

 3. Otherwise, store the value, 'obj.foo'.

Step 2 works for "normal" methods defined in Python, for Python methods taking
'self' as the only (non-defaulted) paramter, and ExternalMethods;  it doesn't
work for DTML Methods.

This is a good reason to learn PythonMethods, if you haven't dived in there
already.

Tres.
-- 
=========================================================
Tres Seaver  tseaver@digicool.com   tseaver@palladion.com