def validate(self, value): super(BasicListField, self).validate(value) if value and not isinstance(value, list): raise ValidationError('Validation failed, not a list.') if self.max_length is not None and len(value) > self.max_length: raise ValidationError('Exceeded {} allowed elements.'.format( self.max_length))
def validate(self, value): super(StringField, self).validate(value) if value and not isinstance(value, six.string_types): raise ValidationError('{} is not a valid value for {}'.format( value, self.__class__.__name__)) if self.max_length is not None and len(value) > self.max_length: raise ValidationError('{}: max length exceeded.'.format(self.name))
def validate(self, value): value = super().validate(value) if value and not isinstance(value, list): raise ValidationError('Validation failed, not a list.') if self.max_length is not None and len(value) > self.max_length: raise ValidationError( f'Exceeded {self.max_length} allowed elements.') return value
def validate(self, value): value = super().validate(value) if value and not isinstance(value, str): raise ValidationError( f'{value} is not a valid value for {type(self).__name__}') if self.max_length is not None and len(value) > self.max_length: raise ValidationError(f'{self.name}: max length exceeded.') return value
def validate(self, value): super(UuidField, self).validate(value) try: UUID(value, version=4) except ValueError: raise ValidationError('{} is not a valid value for {}'.format( value, self.__class__.__name__))
def validate(self, value): if value and not isinstance(value, bool): raise ValidationError( '{} is not a valid value for {}'.format( value, self.__class__.__name__ ) ) return value
def validate(self, value): value = super().validate(value) try: UUID(value, version=4) return value except ValueError: raise ValidationError( f'{value} is not a valid value for {type(self).__name__}')
def validate(self, value): try: return float(value) except ValueError: raise ValidationError( '{} is not a valid value for {}'.format( value, self.__class__.__name__ ) )
def __set__(self, instance, value): # using empty as sentinel, value can be only set once - first time if self.read_only and instance._data[self.name] is not empty: raise ReadOnlyPropertyError( 'Property {} is marked as read only!'.format(self.name)) # handle metadata. If metadata is set use _overwrite_metadata to signal # that the resource should be overwritten. if self.name == 'metadata': instance._overwrite_metadata = True if value is None: raise ValidationError('Not a valid dictionary!') value = self.validate(value) try: current_value = instance._data[self.name] if current_value == value: return except KeyError: pass instance._dirty[self.name] = value instance._data[self.name] = value
def validate(self, value): if value and not isinstance(value, bool): raise ValidationError( '{value} is not a valid value for {type(self).__name__}') return value
def validate(self, value): try: return float(value) except ValueError: raise ValidationError( f'{value} is not a valid value for {type(self).__name__}')
def validate(self, value): if value and not isinstance(value, six.integer_types): raise ValidationError('{} is not a valid value for {}'.format( value, self.__class__.__name__))