This method iterates on every key (attribute and relation) and calls validateValueForKey for each of them, using the stored value as the parameter 'value'.
You can also define your own global validation method, like:
from Modeling import Validation def validateForSave(self): "Validate " error=Validation.ValidationException() try: CustomObject.validateForSave(self) except Validation.ValidationException, exc: error.aggregateException(exc) # Your custom bizness logic goes here if self.getFirstName()=='John': # No John, except the One if self.getLastName()!='Cleese': error.aggregateError(Validation.CUSTOM_OBJECT_VALIDATION, Validation.OBJECT_WIDE_KEY) error.finalize() # raises, if appropriate
Now suppose that our object aWriter
stores Jleese
for
lastName and John
for firstName. The dictionary of
errors stored in the raised exception, after validateForSave is
called, will be:
{ 'OBJECT_WIDE_VALIDATION': ['Validation of object as a whole failed', 'Custom validation of object as a whole failed'], 'lastName': ['Custom validation of key failed'], }
The value Validation.OBJECT_WIDE_KEY is used to report global validation errors. You will find it as soon as an error has been detected while validating. Here you find an other value for that key, Validation.CUSTOM_OBJECT_VALIDATION, indicating that our own code did not validate the values as well. Note that the validation for key lastName has failed as well and is also reported.
Comments are welcome: Sebastien Bigaret / Modeling Home Page