Example #1
0
    def _process_field_error(self, e: InvalidModelFieldError, field: str):
        if not e.field:
            e.field = field

        if not e.model:
            e.model = self
        raise e
Example #2
0
    def validate(self, value):
        if not value:
            return

        if not isinstance(value, self.type):
            raise InvalidModelFieldError(
                "should be an instance of '{}'".format(self.type.__name__))
Example #3
0
 def __set__(self, instance, value):
     if value is not None and not isinstance(value, self.model):
         try:
             value = self.model(value)
         except ValueError:
             available = [e.value for e in self.model]
             raise InvalidModelFieldError("{0} is not a valid option. Use one of {1}".format(value, available))
     super().__set__(instance, value)
Example #4
0
    def validate(self, value):
        if not value:
            return

        if not isinstance(value, collections.MutableSequence):
            raise InvalidModelFieldError('should be a list')

        for i in value:
            for validator in self.validators:
                validator(i)
Example #5
0
    def validate(self, value):
        if not value:
            return

        if value not in self.choices:
            raise InvalidModelFieldError('{0} should be in {1}'.format(value, self.choices))
Example #6
0
    def validate(self, value):
        if not value:
            return

        if not isinstance(value, bool):
            raise InvalidModelFieldError('{0} should be a boolean'.format(value))
Example #7
0
    def validate(self, value):
        if not value:
            return

        if not isinstance(value, int):
            raise InvalidModelFieldError('{0} should be an integer'.format(value))
Example #8
0
    def validate(self, value):
        if not value:
            return

        if not isinstance(value, str):
            raise InvalidModelFieldError('{0} should be a string'.format(value))
Example #9
0
 def validate(self, value):
     if value is None:
         raise InvalidModelFieldError('is required')
Example #10
0
    def validate(self, value):
        if not value:
            return

        if not isinstance(value, float):
            raise InvalidModelFieldError("{0} should be a float".format(value))