[Zope] a form, a script and the namespace: please help a newbie !

Dieter Maurer dieter@handshake.de
Sun, 26 Aug 2001 19:14:59 +0200 (CEST)


Giuseppe Bonelli writes:
 > ...
 > DTML method fooEdit
 > [...]
 > <dtml-call normalize_default_values>
 >    <form ...>
 >      <textarea name="description"><dtml-var description></textarea>
 >    <input type="submit" ...>
 > 
 > Python script normalize_defaul_values
 > [...]
 > description=context.description
 > if description=='bar': description=''
 > return context.REQUEST.set('description',description)
 > 
 > What happens with this code:
 > when I view foo_instance/foo_Edit, 'description' is always 'bar', not '' as I'd expect.
The reason:

    "REQUEST" is far down the DTML namespace, lower than the object itself.

    Therefore your "<dtml-var description>" find the (unchanged)
    "description" attribute value of "context" and not
    the new one set in "REQUEST".

The work around:

    <dtml-with REQUEST>
      ....
      <dtml-var description>
      ....
    </dtml-with>

This pushed "REQUEST" on top of the DTML namespace such that
its definitions are examined before that of "context".


Dieter