def validate(self, value, context=None): try: int(value) except (ValueError, TypeError): raise ValidationError(message=self.message) if int(value) != value: raise ValidationError(message=self.message)
def validate(self, value, context=None): try: if ( value and validators.length(value, max=self.max_length) is not True ): raise ValidationError(message=self.message) except (TypeError, AssertionError): raise ValidationError(message=self.message)
def validate(self, value, context=None): try: if ( value is not None and value != '' and validators.between( value, max=self.max, ) is not True ): raise ValidationError(message=self.message) except (TypeError, AssertionError): raise ValidationError(message=self.message)
def validate(self, value): if not value: return try: json.loads(value) except ValueError: raise ValidationError('Introduced data is not a valid json object')
def validate(self, value, context=None): regex_matches = self.regex.search(str(value)) invalid_input = ( regex_matches if self.inverse_match else not regex_matches ) if invalid_input: raise ValidationError(self.message)
def validate(self, value, context=None): if value is None or value == '': return d_from = None d_to = None try: if value['from']: d_from = datetime.strptime(value['from'], self.format_pattern) if value['to']: d_to = datetime.strptime(value['to'], self.format_pattern) except (TypeError, ValueError): raise ValidationError(message=self.message) if d_from and d_to: if d_from > d_to: raise ValidationError(message=self.message)
def validate(self, value, context=None): if value is None or value == '': return try: datetime.strptime(value, self.format_pattern) except (TypeError, ValueError): raise ValidationError(message=self.message)
def validate(self, value, context=None): if value and validators.url(value) is not True: raise ValidationError(self.message)
def validate(self, value, context=None): if not value: raise ValidationError(self.message)
def validate(self, value, context=None): if not value: return if not value.isidentifier(): raise ValidationError( 'Introduced data is not a valid Python identifier')