a form, a script and the namespace: please help a newbie !
I _really_ need help on understanding why this does not work. What I'm trying to do: I want to change, from a python script called from a dtlm method, a class instance property value. The code I use: let 'description' be a property of the class instance foo; initially, suppose foo_instance.description='bar' 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. Notes: If I insert a <dtml-var "REQUEST"> inside the foo.edit DTML method, the 'description' property is shown as having value '', as expected. I have also tried to add to the script "return context.manage_changeProperties({REQUEST['description']:description})", but the result is the same. If I use a new property name, for example new_description, everything works as expected. Questions: How can I change the _existing_ foo_instance.description property from a python script ? Obviously I am missing something important about namespaces: someone can, _please_, point me in the right direction ? TIA, --peppo
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
participants (2)
-
Dieter Maurer -
Giuseppe Bonelli