[Zope] neted dtml-in and ZSQL methods

Dieter Maurer dieter@handshake.de
Fri, 16 Jun 2000 20:52:13 +0200 (CEST)


jpenny@universal-fasteners.com writes:
 > Suppose, you have a database, items,  that has fields product and scheme.
 > 
 > You are processing a form that has field old_product and new_product.
 > 
 > You have a ZSQL method, get_scheme, with parameter old_product and body
 > select * from items where product = <dtml-sqlvar old_product type=string>.
 > 
 > You also have a ZSQL method, new_scheme, with parameter new_product and
 > scheme.
 > 
 > Observation:
 > 
 > <dtml-in get_scheme>
 >      <dtml-call new_scheme>
 > </dtml-in>
 > 
 > fails, with message
 > 
 >           Zope Error
 > 
 >           Zope has encountered an error while publishing this resource. 
 > 
 >           Error Type: NameError
 >           Error Value: scheme
I can across the same thing yesterday.

The explantion:
  SQL methods are much more stupid than DTML methods!
  If used in the way you do it, SQL methods look only
  in the REQUEST object and not in the namespace.

  This means (if called from a WEB request, i.e. REQUEST is defined):
    <dtml-call new_scheme> is equivalent to <dtml-call "new_scheme(REQUEST)">.
  Your <dtml-in>, however, has placed the fields into the
  namespace "_" and not in the REQUEST object.

  You cannot use <dtml-call "new_scheme(_)"> either, because
  SQL methods require a "get" method from their first parameter
  ("_" does not have it).

For the moment, you have to use on of these ways:

  1.  <dtml-call "new_scheme(new_product=new_product, scheme=scheme)">
or
  2.  <dtml-call "REQUEST.set('new_product',new_product)">
      <dtml-call "REQUEST.set('scheme',scheme)">
      <dtml-call new_scheme>

I prefered 1. in my solution.


Dieter