class InvalidField(Exception):
pass
class ValidatorConverter:
def _attemptConvert(self, value):
v = self._validate(value)
if v:
raise InvalidField, v
else:
return self._convert(value)
def _convert(self, value):
"""By default, all validators do no conversion... they just return what they are given"""
return value
def _validate(self, value):
"""Return an error message, or None if valid"""
return None
class FormValidator:
"""
This is just a skeleton for what an actual form validator should
do.
The important method is .validate(), of course. It gets passed a
dictionary of the (processed) values from the form. If you have
.validatePartialForm() return True, it will be called regardless
of whether any of the fields have validation errors on thier own.
Raise an error (as below) if you don't like something about the field
values.
Return None on no errors.
"""
def validatePartialForm(self):
return None
def validate(self, fieldDict):
raise InvalidField, "This FormValidator hasn't been written, yet!"