Example #1
0
    def validate(self, quiet=False):
        for child in self.children:
            child.validate(quiet)

        BaseField.validate(self, quiet)

        self.value = self.to_dict()[self.name]
        self.is_validated = True
Example #2
0
 def __init__(self, name, fields, description=None):
     """
     Field to use when one key in dict can contain different values, e.g. list or string, based on usage.
     This field does not accept any validators or transformers. Pass them to the field in `self.fields` instead
     :param name: Field name
     :param fields: Dict of {type.__name__: field} values
     :type fields: dict
     :param description: Field description
     """
     BaseField.__init__(self, name, description)
     self.fields = fields
     self.field_type = None
Example #3
0
 def __init__(self,
              name,
              description=None,
              validators=None,
              transform_before=None,
              transform_after=None):
     """
     Field for lists
     :param name: Field name
     :param description: Field description
     :param validators: List of validators
     :param transform_before: List of transformations before validation
     :param transform_after: List of transformations after validation
     """
     BaseField.__init__(self, name, description, validators,
                        transform_before, transform_after)
     self.field_type = list
     self.validators = [IsInstance(self.field_type)] + (validators or [])
Example #4
0
    def __init__(self,
                 name,
                 children,
                 description=None,
                 validators=None,
                 transform_before=None,
                 transform_after=None):
        """
        DictField, for nesting fields
        :param name: Field name
        :param children: List of subfields
        :param description: Field description
        :param validators: List of validators
        :param transform_before: List of transformations before validation
        :param transform_after: List of transformations after validation
        """
        BaseField.__init__(self, name, description, validators,
                           transform_before, transform_after)
        self.field_type = dict
        self.children = children

        assert self.children, "%s must have one or more children" % self.__class__.__name__