[Zope] How to define class in Python script instance?

Skip Montanaro skip@pobox.com
Sat, 23 Nov 2002 23:02:45 -0600


I wrote:

    Skip> I'm struggling to understand how <dtml-tree> is supposed to work
    Skip> with Python scripts.  I have this simple dtml document:
    ... [ much elided ] ...

The solution to my problem was much easier than I originally thought.
Problem was, all the ZSQL methods for querying the various tables returned
an id and a title-like field which was generally different for each table:
title, client_name, name, etc.  The solution was to coerce my ZSQL methods
to returning results with the two interesting fields named as I wished.  For
example, instead of 

    <params>
    client_id
    </params>
    select id,title from project
      <dtml-sqlgroup where>
          <dtml-sqltest name=client_id op=eq type=int optional>
      </dtml-sqlgroup>
      order by title
    ;

I had modified the select to use "field as alias" syntax:

    <params>
    client_id
    </params>
    select id,title,title as name,id as objectid from project
      <dtml-sqlgroup where>
          <dtml-sqltest name=client_id op=eq type=int optional>
      </dtml-sqlgroup>
      order by title
    ;

That way the callers who expected "id" and "title" got what they were after
and the <dtml-tree> got "objectid" and "name" consistently from the various
ZSQL methods (four in all, one for each of four different tables).

-- 
Skip Montanaro - skip@pobox.com
http://www.mojam.com/
http://www.musi-cal.com/