Perfect (almost ;-), thanks a lot!
for future reference, the attribute name (key) was needed
in create_validator(cls) to access the correct validate method:
@staticmethod
def _create_validator(key, cls):
def validate(target, value, oldvalue, initiator):
if not cls._type_[key].validate(value):
raise ValueError("incorrect value '%s' for '%s' in '%s'" %
(str(value), key, cls.__name__))
return validate
def create_validators(self):
for cls in self.itervalues():
for fld in cls._type_.fields():
key = fld.key()
attribute = getattr(cls, key)
event.listen(attribute, "set", self._create_validator(key,
cls))
debug_print('created validator for %s in %s' % (key,
cls.__name__))
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/I-TQaC4YCqYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.