def getFirstValidationError(obj): fields = get_fields(obj) for field_name in fields: value = getattr(obj, field_name) if type(value) == FailedValidation: attributeName = field_name[field_name.rfind('_') + 1:] return 'Attribute "{0}" is invalid due to: {1}'.format(attributeName, value.error) return ''
def getFirstValidationError(obj): fields = get_fields(obj) for field_name in fields: value = getattr(obj, field_name) if type(value) == FailedValidation: attributeName = field_name[field_name.rfind('_') + 1:] return 'Attribute "{0}" is invalid due to: {1}'.format( attributeName, value.error) return ''
def isObjectValid(obj): """ Checks if an object is valid. This means that the object has no attribute of type FailedValidation :param obj: The object instance to be tested :type obj: object :returns: Boolean """ fields = get_fields(obj) for field_name in fields: value = getattr(obj, field_name) if type(value) == FailedValidation: return False return True