def __call__(self, attrs):
        """Performs validation (called by DRF)."""
        errors = {}
        for field in self.fields:
            if self.instance and is_blank(getattr(self.instance, field)):
                continue

            if self.partial and field not in attrs:
                continue

            if is_blank(attrs.get(field)):
                errors[field] = self.required_message

        if errors:
            raise serializers.ValidationError(errors)
示例#2
0
 def __call__(self, combiner) -> bool:
     """Test whether all of the fields are blank."""
     return all(is_blank(combiner[field]) for field in self._fields)
def test_is_blank(value, blank):
    """Tests is_blank() for various values."""
    assert is_blank(value) == blank