text.py 586 Bytes
Newer Older
1
2
3
4
5
6
from rest_framework.validators import ValidationError


def validate_text(config, string):
    string = str(string)  # might cause error with number ?
    try:
7
        validators = config["validators"]
8
9
        for validator in validators:
            validator_content = validators[validator]
10
            if validator == "max_length":
11
                if len(string) > validator_content:
12
                    raise ValidationError("Your text is too long !")
13
14
15
16
17
            else:
                raise Exception("Dev, you have implement something here...")

    except KeyError:
        pass