Exemple #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
Exemple #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__))
Exemple #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)
Exemple #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)
Exemple #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))
Exemple #6
0
    def validate(self, value):
        if not value:
            return

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

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

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

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