[Zope] What is the Python script that is similar to a dtml-in call

Small Business Services toolkit at magma.ca
Mon May 31 07:51:42 EDT 2004


<snip>
From: Larry McDonnell

I need some advice. I still use dtml calls in my systems. My problem is if
the user is searching for a record but the record is not found. The call is
as follows:

<dtml-call "REQUEST.set('serial_number', serial_number)">

<dtml-in lookup_header_record>
  <dtml-call "REQUEST.set('equip_type', equip_type)">
  <dtml-call "REQUEST.set('pr', pr)">
</dtml-in>

If the record is not found I get this error:

Error Type: KeyError
Error Value: equip_type

True statement since there is not record and further in the form I am trying
to output this variable.
Are there any examples that either traps for an error or python script that
can also lookup the record and true a found/not found status.
</snip>

A couple of possibilities

 <dtml-call "REQUEST.set('equip_type',  REQUEST.get('equip_type',
'None') )">
    This REQUEST.get will return 'None' (or whatever value you assign) if
'equip_type' is not found

or

 <dmtl-if "REQUEST.has_key('equip_type')">
    <dtml-call "REQUEST.set('equip_type', equip_type)">
  </dtml-if>
    This will only do the assignment if 'equip_type' exists.


The above can be done in dtml or python script.

HTH

Jonathan








More information about the Zope mailing list