[Zope-dev] ZPatterns: SAVING doesn't tolerate missing attributes

Steve Alexander steve@cat-box.net
Sat, 06 Jan 2001 16:48:30 +0000


In SkinScript such as

   WHEN eventspec CALL expression SAVING mementolist

if any of the mementos in mementolist are not found, the script raises a 
KeyError.

I'd like a way of saving a memento if it exists, or NOT_FOUND otherwise.

For example, an Executive might have a CompanyCar.

WITH CompanyCars.getCar(self.car_id) or NOT_FOUND COMPUTE
   car=RESULT,
   car_registration=registration
OTHERWISE LET
   car=NOT_FOUND,
   car_registration="no car"

When an Executive changes her car for a different one, I want to perform 
certain actions on the old car, and certain on the new car:

WHEN OBJECT CHANGED CALL
   HAS_CHANGED('car_id') and
   (self.car_id and CompanyCars.getItem(self.car_id).decommission(),
    ORIGINAL['car_id'] and OLD['car'].commission())
SAVING car

However, I can't do this if the executive is being assigned a car from a 
state of having no car. It fails with a KeyError because the ZPatterns 
machinery can't save "car".

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net