What is the Python script that is similar to a dtml-in call
Hi, 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. Thanks, Larry
<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
Thanks Jonathan for the quick answer. I'll give them a try. Larry Small Business Services wrote:
<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
--On Montag, 31. Mai 2004 7:37 Uhr -0400 Larry McDonnell <larry@technologyinedu.com> wrote:
Hi,
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>
Modifying the REQUEST using REQUEST.set() is in general bad-style and a DON'T DO IT.
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.
Look at the Python documentation try...except or whatever....you questions sounds like you really want to learn Python :-) -aj
Hi, I use the serial_number variable to look up the record. Does the dtml-call return a status back if the record is not found? Thanks, Larry Andreas Jung wrote:
--On Montag, 31. Mai 2004 7:37 Uhr -0400 Larry McDonnell <larry@technologyinedu.com> wrote:
Hi,
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>
Modifying the REQUEST using REQUEST.set() is in general bad-style and a DON'T DO IT.
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.
Look at the Python documentation try...except or whatever....you questions sounds like you really want to learn Python :-)
-aj
From: "Larry McDonnell" <larry@technologyinedu.com>
I use the serial_number variable to look up the record. Does the dtml-call return a status back if the record is not found?
<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>
By 'record' do you mean the variable 'serial_number' in the above REQUEST.set statement? dtml-call won't 'return' anything. If, in your REQUEST.set('label', variable) statement 'variable' is not defined you will get an error. Jonathan
Hi, Within the dtml-in statement, I use serial_number to find the record in the db. I checking for a valid serial number but what is return from the dtml-in statement if the serial number lookup is not found. Larry Small Business Services wrote:
From: "Larry McDonnell" <larry@technologyinedu.com>
I use the serial_number variable to look up the record. Does the dtml-call return a status back if the record is not found?
<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>
By 'record' do you mean the variable 'serial_number' in the above REQUEST.set statement?
dtml-call won't 'return' anything. If, in your REQUEST.set('label', variable) statement 'variable' is not defined you will get an error.
Jonathan
<snip> From: Larry McDonnell Within the dtml-in statement, I use serial_number to find the record in the db. I checking for a valid serial number but what is return from the dtml-in statement if the serial number lookup is not found. </snip> If you are doing individual db look-ups within a dtml-in loop then you need to check the return value from each db look-up call: eg. <dtml-in lookup_header_record> <dtml-let rstatus="dbGet(_['sequence-item'])"> <dtml-if "rstatus != 'success'"> No success for item: <dtml-var sequence-item><br> </dtml-if> </dtml-let> </dtml-in> Alternatively, you could store the 'failed' returns and then handle them all at once: <dtml-call "REQUEST.set('errflag', {})"> <dtml-in lookup_header_record> <dtml-let rstatus="dbGet(_['sequence-item'])"> ***dbGet is your db lookup function <dtml-if "rstatus != 'success'"> *** dbGet must return some status value <dtml-call "errflag.update({_['sequence-item'] : 'failed'})"> </dtml-if> </dtml-let> </dtml-in> <dtml-if "errflag != {}"> Errors during db lookup: <dtml-var errflag> </dtml-if> or <dtml-if "errflag != {}"> <dmtl-in "errflag.keys()"> Errors during db lookup: <dtml-var "errflag[_['sequence-item']]"> failed<br> </dtml-in> </dtml-if> HTH Jonathan Caveat: above code is NOT tested
Hi, Thanks Jonathan, this is what I was looking for. Larry Small Business Services wrote:
<snip> From: Larry McDonnell
Within the dtml-in statement, I use serial_number to find the record in the db. I checking for a valid serial number but what is return from the dtml-in statement if the serial number lookup is not found. </snip>
If you are doing individual db look-ups within a dtml-in loop then you need to check the return value from each db look-up call:
eg.
<dtml-in lookup_header_record> <dtml-let rstatus="dbGet(_['sequence-item'])"> <dtml-if "rstatus != 'success'"> No success for item: <dtml-var sequence-item><br> </dtml-if> </dtml-let> </dtml-in>
Alternatively, you could store the 'failed' returns and then handle them all at once:
<dtml-call "REQUEST.set('errflag', {})"> <dtml-in lookup_header_record> <dtml-let rstatus="dbGet(_['sequence-item'])"> ***dbGet is your db lookup function <dtml-if "rstatus != 'success'"> *** dbGet must return some status value <dtml-call "errflag.update({_['sequence-item'] : 'failed'})"> </dtml-if> </dtml-let> </dtml-in>
<dtml-if "errflag != {}"> Errors during db lookup: <dtml-var errflag> </dtml-if>
or
<dtml-if "errflag != {}"> <dmtl-in "errflag.keys()"> Errors during db lookup: <dtml-var "errflag[_['sequence-item']]"> failed<br> </dtml-in> </dtml-if>
HTH
Jonathan
Caveat: above code is NOT tested
I am trying to pack a DBTab mounted database via an external method. I have two separate db's mounted (Data.fs, MyDB.fs) and only want to pack MyDB.fs I have tried: self.Control_Panel.Database.MyDB.manage_pack() with no luck, it generates the following error: Error Type: AttributeError Error Value: MyDB Error Traceback: Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module OFS.DTMLMethod, line 126, in __call__ Module DocumentTemplate.DT_String, line 474, in __call__ Module Products.ExternalMethod.ExternalMethod, line 231, in __call__ __traceback_info__: ((), {}, None) Module /apps/zope/Extensions/jhtmp.py, line 8, in jhtmp AttributeError: MyDB I have looked at the source for the 'pack' button (in Control_Panel/Database/MyDB) but found no clues (the form just calls 'manage_pack' directly with no reference to which database should be packed. I have also looked at the source for manage_pack and found no clues. Somebody must have done this! Thanks, Jonathan
Small Business Services wrote at 2004-5-31 08:00 -0400:
I am trying to pack a DBTab mounted database via an external method. I have two separate db's mounted (Data.fs, MyDB.fs) and only want to pack MyDB.fs
I have tried: self.Control_Panel.Database.MyDB.manage_pack() with no luck, it generates the following error:
Error Type: AttributeError Error Value: MyDB
Try: "self.unrestrictedTraverse('Control_Panel/Database/MyDB').manage_pack(0)". It is usually adviceable to use "[un]restrictedTraverse" rather than explicit attribute traversal as many containers provide a subscription access for subobjects. -- Dieter
Dieter, The unrestrictedTraverse(...).manage_pack worked perfectly! Thank you very much! Jonathan ----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Small Business Services" <toolkit@magma.ca> Cc: <zope@zope.org> Sent: May 31, 2004 1:46 PM Subject: Re: [Zope] Packing a DBTab database
Small Business Services wrote at 2004-5-31 08:00 -0400:
I am trying to pack a DBTab mounted database via an external method. I have two separate db's mounted (Data.fs, MyDB.fs) and only want to pack MyDB.fs
I have tried: self.Control_Panel.Database.MyDB.manage_pack() with no luck, it generates the following error:
Error Type: AttributeError Error Value: MyDB
Try: "self.unrestrictedTraverse('Control_Panel/Database/MyDB').manage_pack(0)".
It is usually adviceable to use "[un]restrictedTraverse" rather than explicit attribute traversal as many containers provide a subscription access for subobjects.
-- Dieter
participants (4)
-
Andreas Jung -
Dieter Maurer -
Larry McDonnell -
Small Business Services