[Zope-dev] External Method Return value?

Jim Penny jpenny@universal-fasteners.com
Wed, 26 Jan 2000 11:19:42 -0500


On Mon, Jan 24, 2000 at 05:43:07PM +0000, Clayton Miller wrote:
> Chris,
> Thanks for the timely response. What I am trying to do is to replace some 
> code that use to be like:
> 
> someDTMLmethod
> --------------
> 	dtml-in "someSQLmethod(anyParams)"
> 		<dtml-var FIELDA>, <dtml-var FIELDB>
> 	/dtml-in
> 
> someSQLmethod
> -------------------------
> 	select FIELDA, FIELDB from some Table ...
> 
> 
> I am attempting to replace this with an external method like:
> 
> someDTMLmethod
> --------------
> 	dtml-in "someExtmethod(anyParams)"
> 		<dtml-var FIELDA>, <dtml-var FIELDB>
> 	/dtml-in
> 
> someExtMethod
> -----------------------
> 	results = self.someSQLmethod(anyParams)
> 	""" further processing of results into new results """
>         return newresults
> 
> someSQLmethod
> -------------------------
> same as above
> 
> 
> How do I get the tuples(python return value) to work as the same
> type of results(old SQLMethod) to the dtml-in?
> Clayton

Hi, Jim Penny here.  You are right, my howto does not address your issue
(explicitly).

I suspect there are two ways of doing this task, an easy one that
you won't like, and a hard one that may like, but won't like to do.

If you think about it in the right way, my howto says that the SQLMethod
returns a list of lists, along with a bunch of auxiliary lists and
dictionaries, some of which have purpose not apparent without finding
and reading the corresponding code.

The hard way to do this task is to simulate the structures that SQLmethod
creates; i.e. you need to create a res structure.  I suspect that you will
not need all of it, but you will certainly need to create a res._schema_items
and the data lists in res[k].

This will take some experimentation;  I don't have time to do this right now,
in fact I haven't had any zope time for at least three weeks.

THe easier way is to simply return a list of lists.
Then do the binding to name yourself (this binding to name is much of 
what the res structure is about!).

That is your DTMLmethod will look like

<dtml-call "REQUEST.set('res', someExtmethod(anyParams)">
<dtml-in "range(len(res))">
	<dtml-call "REQUEST.set('FIELDA', _['res'][_['sequence-item']][0]">
	<dtml-call "REQUEST.set('FIELDB', _['res'][_['sequence-item']][1]">
        ...
</dtml-in>

This is admittedly ugly and may not even work, I am typing this without
testing, but I am reasonably sure that it is correct.  The simpler expression
        <dtml-call "REQUEST.set('FIELDA', res[_['sequence-item']][0]">
may also work.

Note to DC.
could you please deprecate the '-'s in structure names;  they seem always
to lead to the _ circumlocution which seems dreadfully confusing to 
beginning Zopatistas.


<dtml-in "range(someExtmethod(params)>
	<dtml-call "REQUEST.set('FIELDA',