def validate(self, value): if not isinstance(value, collections.MutableSequence): raise errors.ValidationError('should be a list') for i in value: for validator in self.validators: validator(i)
def validate(self): """This method validates the entire `model`. That is, validates all the :mod:`fields` within this model. If some `field` validation fails, then this method raises the same exception that the :func:`field.validate` method had raised, but with the field name prepended. """ for name, field in self._fields.items(): try: field.validate(getattr(self, name)) except errors.ValidationError as err: raise errors.ValidationError('%s %s' % (name, err))
def validate(self): raise errors.ValidationError()
def validator2(value): if value == 'foo': raise errors.ValidationError()
def validate(self, value): if not isinstance(value, bool): raise errors.ValidationError('should be a boolean')
def validate(self, value): if not isinstance(value, float): raise errors.ValidationError('should be a float')
def validate(self, value): if not isinstance(value, int): raise errors.ValidationError('should be an integer')
def validate(self, value): if not isinstance(value, str): raise errors.ValidationError('should be a string')
def validate(self, value): if value not in self.choices: raise errors.ValidationError('should be in {}'.format(self.choices))
def validate(self, value): if value is None: raise errors.ValidationError('is required')
def validate(self, value): if not isinstance(value, datetime.datetime): raise errors.ValidationError('should be a datetime')
def validate(self, value): super(Email, self).validate(value) if self.pattern.match(value) is None: raise errors.ValidationError('should be a valid email')
def validate(self, value): if not isinstance(value, self.model): raise errors.ValidationError( "should be an instance of '{}'".format(self.model.__name__)) value.validate()
def inner_validator(value): if value == 'bar': raise errors.ValidationError('invalid')
def validate(self, value): super(URI, self).validate(value) if self.uri_regex.match(value) is None: raise errors.ValidationError('should be a valid URI')
def validate(self, value): super(IP, self).validate(value) if self.ipv4.match(value) is None and self.ipv6 is None: raise errors.ValidationError( 'should be a valid IPv4 or IPv6 address')