SV: [Zope] Render SQL method as lines

Casey Duncan cduncan@kaivo.com
Tue, 20 Mar 2001 11:21:14 -0700


Kenneth Ellested wrote:
> 
> Hmmm... not yet !
> 
> I was trying to convert a SQL method into lines, which as far as I can
> understand is newline terminated (LF?). I think that my attempt below
> returns CR/LF.
> When I try to insert a new property (multiple selection) in another object,
> and add my DTML method as the value parameter, zope says "Strings are not
> allowed as input to the in tag". If I specify the SQL method directly, I get
> the row objects (I think), and not the actual column. So I'd like to
> transform the SQL column into lines...
> 
> Hope you understand what I mean !
> 
> Thanks
> 


The SQL method returns a list of brains. The DTML Method returns a
string (by default). I would suggest using a python script to return a
list of strings from the sql method like so:

list = []
for row in context.sqlMethod(context.REQUEST):
    list.append(row.field)
return list

However, a lines property does not take a list as input, it takes
newline delimited string, so the following python script might work
better (untested):

import string
list = []
for row in context.sqlMethod(context.REQUEST):
    list.append(row.field)
return string.join(list, '\n')

-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>